Skip to content

Commit

Permalink
On tender validate, also set sent_at
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Nov 30, 2023
1 parent a12fc48 commit 9a416e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 3 additions & 4 deletions lemarche/tenders/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 9a416e0

Please sign in to comment.