From 70a62238a3ced64aea272faa572c0d2a921c1eea Mon Sep 17 00:00:00 2001 From: "madjid.asa" Date: Fri, 18 Oct 2024 11:53:53 +0200 Subject: [PATCH] fix the synchro when it's sending to partners else catch error and send it to admin --- lemarche/tenders/admin.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lemarche/tenders/admin.py b/lemarche/tenders/admin.py index de27a5980..9b518ef71 100644 --- a/lemarche/tenders/admin.py +++ b/lemarche/tenders/admin.py @@ -789,21 +789,20 @@ def response_change(self, request, obj: Tender): if request.POST.get("_validate_send_to_siaes"): obj.set_validated() if obj.amount_int > settings.BREVO_TENDERS_MIN_AMOUNT_TO_SEND: - api_brevo.create_deal(tender=obj, owner_email=request.user.email) - # we link deal(tender) with author contact - api_brevo.link_deal_with_contact_list(tender=obj) - self.message_user(request, "Ce dépôt de besoin a été synchronisé avec Brevo") + try: + api_brevo.create_deal(tender=obj, owner_email=request.user.email) + # we link deal(tender) with author contact + api_brevo.link_deal_with_contact_list(tender=obj) + self.message_user(request, "Ce dépôt de besoin a été synchronisé avec Brevo") + except Exception as e: + self.message_user(request, f"Erreur dans la synchronisation du DDB avec Brevo {str(e)}") self.message_user(request, "Ce dépôt de besoin a été validé. Il sera envoyé en temps voulu :)") return HttpResponseRedirect(".") if request.POST.get("_validate_send_to_commercial_partners"): obj.send_to_commercial_partners_only = True obj.set_validated() - if obj.amount_int > settings.BREVO_TENDERS_MIN_AMOUNT_TO_SEND: - api_brevo.create_deal(tender=obj, owner_email=request.user.email) - # we link deal(tender) with author contact - api_brevo.link_deal_with_contact_list(tender=obj) - self.message_user(request, "Ce dépôt de besoin a été synchronisé avec Brevo") - self.message_user(request, "Ce dépôt de besoin a été validé. Il sera envoyé en temps voulu :)") + # we don't need to send it in the crm, parteners manage them + self.message_user(request, "Ce dépôt de besoin a été validé. Il sera envoyé aux partenaires :)") return HttpResponseRedirect(".") elif request.POST.get("_restart_tender"): restart_send_tender_task(tender=obj)