From 320473b8ffbfe9b33667593dad99b359f3fd74f6 Mon Sep 17 00:00:00 2001 From: Chloend Date: Sun, 15 Dec 2024 19:14:16 +0100 Subject: [PATCH] Send emails if tender needs modification or is rejected --- lemarche/tenders/admin.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lemarche/tenders/admin.py b/lemarche/tenders/admin.py index 9c6d87a9a..90b2ce892 100644 --- a/lemarche/tenders/admin.py +++ b/lemarche/tenders/admin.py @@ -25,7 +25,11 @@ 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 +from lemarche.www.tenders.tasks import ( + restart_send_tender_task, + send_tender_author_modification_request, + send_tender_author_reject_message, +) class KindFilter(MultiChoice): @@ -817,6 +821,18 @@ def response_change(self, request, obj: Tender): # 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(".") + if obj.email_sent_for_modification: + if not obj._original_email_sent_for_modification: + send_tender_author_modification_request(tender=obj) + self.message_user(request, "Une demande de modification a été envoyée à l'auteur du besoin") + obj.email_sent_for_modification = True + obj.status = tender_constants.STATUS_DRAFT + obj.save(update_fields=["email_sent_for_modification", "status"]) + return HttpResponseRedirect(".") + if obj.status == tender_constants.STATUS_REJECTED: + send_tender_author_reject_message(tender=obj) + self.message_user(request, "Un email a été envoyé à l'auteur du besoin") + return HttpResponseRedirect(".") elif request.POST.get("_restart_tender"): restart_send_tender_task(tender=obj) self.message_user(request, "Ce dépôt de besoin a été renvoyé aux structures")