From 55d6ebfcc9440f438da9e871d1f02c00f0857059 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Thu, 22 Feb 2024 14:22:37 +0100 Subject: [PATCH] Brevo: API to create companies (siae) --- config/settings/base.py | 1 + lemarche/utils/apis/api_brevo.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) 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/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,