diff --git a/config/settings/base.py b/config/settings/base.py index 6bd8d14a4..12bbc6937 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -861,6 +861,7 @@ "from lemarche.utils import constants", "from lemarche.siaes import constants as siae_constants", "from lemarche.tenders import constants as tender_constants", + "from lemarche.utils.apis import api_brevo, api_mailjet", ] FORM_RENDERER = "django.forms.renderers.TemplatesSetting" diff --git a/lemarche/siaes/models.py b/lemarche/siaes/models.py index f67140c1d..fe1c8d6ca 100644 --- a/lemarche/siaes/models.py +++ b/lemarche/siaes/models.py @@ -26,6 +26,7 @@ from lemarche.utils.constants import DEPARTMENTS_PRETTY, RECALCULATED_FIELD_HELP_TEXT, REGIONS_PRETTY from lemarche.utils.data import round_by_base from lemarche.utils.fields import ChoiceArrayField +from lemarche.utils.urls import get_admin_url_object def get_region_filter(perimeter): @@ -1230,6 +1231,9 @@ def siae_user_requests_pending_count(self): def get_absolute_url(self): return reverse("siae:detail", kwargs={"slug": self.slug}) + def get_admin_url(self): + return get_admin_url_object(self) + def set_super_badge(self): update_fields_list = ["super_badge"] siae_super_badge_current_value = self.super_badge diff --git a/lemarche/templates/siaes/_detail_admin_extra_info.html b/lemarche/templates/siaes/_detail_admin_extra_info.html index 55cb3d9f9..a72b224ba 100644 --- a/lemarche/templates/siaes/_detail_admin_extra_info.html +++ b/lemarche/templates/siaes/_detail_admin_extra_info.html @@ -24,7 +24,7 @@

Informations Admin

{% endif %}
  • - + Lien vers l'admin  diff --git a/lemarche/utils/apis/api_brevo.py b/lemarche/utils/apis/api_brevo.py index db5b04c4e..8082d68fb 100644 --- a/lemarche/utils/apis/api_brevo.py +++ b/lemarche/utils/apis/api_brevo.py @@ -6,7 +6,9 @@ from huey.contrib.djhuey import task from sib_api_v3_sdk.rest import ApiException +from lemarche.siaes.models import Siae from lemarche.users.models import User +from lemarche.utils.urls import get_admin_url_object, get_share_url_object logger = logging.getLogger(__name__) @@ -65,6 +67,28 @@ def remove_contact_from_list(user: User, list_id: int): logger.error("Exception when calling Brevo->ContactsApi->remove_contact_from_list: %s\n" % e) +def create_company(siae: Siae): + api_client = get_api_client() + api_instance = sib_api_v3_sdk.CompaniesApi(api_client) + new_company = sib_api_v3_sdk.Body( + name=siae.name, + attributes={ + "id": siae.id, + "siae": True, + "kind": siae.kind, + "domain": siae.website, + "link_app": get_share_url_object(siae), + "link_admin": get_admin_url_object(siae), + }, + ) + + try: + api_response = api_instance.companies_post(new_company) + logger.info("Succes Brevo->CompaniesApi->create_company: %s\n" % api_response) + except ApiException as e: + logger.error("Exception when calling Brevo->CompaniesApi->create_company: %s\n" % e) + + @task() def send_transactional_email_with_template( template_id: int,