diff --git a/lemarche/tenders/admin.py b/lemarche/tenders/admin.py index 3662ad84e..2d2c9a2a4 100644 --- a/lemarche/tenders/admin.py +++ b/lemarche/tenders/admin.py @@ -95,9 +95,9 @@ class TenderQuestionInline(admin.TabularInline): extra = 0 -def update_and_send_tender_task(tender: Tender): +def validate_and_send_tender_task(tender: Tender): # 1) validate the tender - tender.set_validated(with_save=True) + tender.set_validated_and_sent(with_save=True) # 2) find the matching Siaes? done in Tender post_save signal send_confirmation_published_email_to_author(tender, nb_matched_siaes=tender.siaes.count()) # 3) send the tender to all matching Siaes & Partners @@ -490,11 +490,10 @@ def logs_display(self, tender=None): def response_change(self, request, obj: Tender): if request.POST.get("_validate_tender"): - update_and_send_tender_task(tender=obj) + validate_and_send_tender_task(tender=obj) self.message_user(request, "Ce dépôt de besoin a été validé et envoyé aux structures") if settings.BITOUBI_ENV == "prod": api_hubspot.create_deal_from_tender(tender=obj) - return HttpResponseRedirect(".") elif request.POST.get("_restart_tender"): restart_send_tender_task(tender=obj) diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index ddcde8c0d..9c63e4a55 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -642,14 +642,20 @@ def is_sent(self) -> bool: def is_validated_or_sent(self) -> bool: return self.validated_at and self.status in [tender_constants.STATUS_VALIDATED, tender_constants.STATUS_SENT] - def set_validated(self, with_save=True): + def set_validated_and_sent(self, with_save=True): self.validated_at = timezone.now() - self.status = tender_constants.STATUS_VALIDATED + self.sent_at = timezone.now() + self.status = tender_constants.STATUS_SENT log_item = { "action": "validate", "date": self.validated_at.isoformat(), } self.logs.append(log_item) + log_item = { + "action": "send", + "date": self.sent_at.isoformat(), + } + self.logs.append(log_item) if with_save: self.save()