diff --git a/config/settings/base.py b/config/settings/base.py index be10a60ab..5c1a4c532 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -864,6 +864,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,