diff --git a/config/settings/base.py b/config/settings/base.py index 7fa588fff..9c51438b0 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -399,6 +399,8 @@ BREVO_TENDERS_AUTHOR_SUPER_SIAES_TEMPLATE_ID = env.int("BREVO_TENDERS_AUTHOR_SUPER_SIAES_TEMPLATE_ID", 61) +BREVO_TENDERS_MIN_AMOUNT_TO_SEND = env.int("BREVO_TENDERS_MIN_AMOUNT_TO_SEND", 34998) + # -- hubspot HUBSPOT_API_KEY = env.str("HUBSPOT_API_KEY", "set-it") HUBSPOT_IS_ACTIVATED = env.bool("HUBSPOT_IS_ACTIVATED", False) diff --git a/lemarche/tenders/admin.py b/lemarche/tenders/admin.py index 1e42e043c..4d087d1e5 100644 --- a/lemarche/tenders/admin.py +++ b/lemarche/tenders/admin.py @@ -1,5 +1,6 @@ from ckeditor.widgets import CKEditorWidget from django import forms +from django.conf import settings from django.contrib import admin from django.contrib.contenttypes.admin import GenericTabularInline from django.core.exceptions import ValidationError @@ -21,6 +22,7 @@ from lemarche.users import constants as user_constants from lemarche.users.models import User from lemarche.utils.admin.admin_site import admin_site +from lemarche.utils.apis import api_brevo from lemarche.utils.fields import ChoiceArrayField, pretty_print_readonly_jsonfield from lemarche.www.tenders.tasks import restart_send_tender_task @@ -765,6 +767,11 @@ def response_change(self, request, obj: Tender): return HttpResponseRedirect("./#structures") # redirect to structures sections if request.POST.get("_validate_tender"): 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_list_contact(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 :)") return HttpResponseRedirect(".") elif request.POST.get("_restart_tender"): diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index 7bac03ef9..d3992a95e 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -981,6 +981,16 @@ def is_validated_or_sent(self) -> bool: def is_partner_approch(self) -> bool: return self.author_id == settings.PARTNER_APPROCH_USER_ID + @property + def amount_int(self) -> int: + if self.amount_exact: + return self.amount_exact + elif self.amount: + return tender_constants.AMOUNT_RANGE_CHOICE_EXACT.get(self.amount) + else: + # else return -1 for unknown + return -1 + def set_validated(self): self.validated_at = timezone.now() self.status = tender_constants.STATUS_VALIDATED