diff --git a/lemarche/templates/tenders/_detail_cocontracting_click_confirm.html b/lemarche/templates/tenders/_detail_cocontracting_click_confirm.html
new file mode 100644
index 000000000..e7fbcba4f
--- /dev/null
+++ b/lemarche/templates/tenders/_detail_cocontracting_click_confirm.html
@@ -0,0 +1,6 @@
+
+
+ Nous avons bien pris en compte votre demande de mise en relation.
+ Notre équipe revient vers vous dans les plus brefs délais.
+
+
diff --git a/lemarche/templates/tenders/_detail_cta_cocontracting.html b/lemarche/templates/tenders/_detail_cta_cocontracting.html
new file mode 100644
index 000000000..ddaf78b9f
--- /dev/null
+++ b/lemarche/templates/tenders/_detail_cta_cocontracting.html
@@ -0,0 +1,19 @@
+
+
+
+
Répondre en co-traitance ?
+
+
Notre équipe vous met en relation avec d’autres structures désireuses de répondre en co-traitance.
+
+ {% if user.is_authenticated %}
+
+ {% else %}
+
+ {% endif %}
+
+
+
diff --git a/lemarche/templates/tenders/cocontracting_notification_email_admin_body.txt b/lemarche/templates/tenders/cocontracting_notification_email_admin_body.txt
new file mode 100644
index 000000000..278c3b98f
--- /dev/null
+++ b/lemarche/templates/tenders/cocontracting_notification_email_admin_body.txt
@@ -0,0 +1,8 @@
+La structure {{ siae_name|safe }} souhaite répondre en co-traitance
+
+Titre : {{ tender_title|safe }}
+Type : {{ tender_kind|safe }}
+Contact email de l'ESI: {{ siae_contact_email|safe }}
+SIRET : {{ siae_siret|safe }}
+
+Lien dans l'admin : {{ tender_admin_url }}
diff --git a/lemarche/www/tenders/tasks.py b/lemarche/www/tenders/tasks.py
index a3cd7445c..06935e47c 100644
--- a/lemarche/www/tenders/tasks.py
+++ b/lemarche/www/tenders/tasks.py
@@ -533,3 +533,26 @@ def send_tenders_author_30_days(tender: Tender, kind="feedback"):
}
tender.logs.append(log_item)
tender.save()
+
+
+def notify_admin_siae_wants_cocontracting(tender: Tender, siae: Siae):
+ email_subject = f"Marché de l'inclusion : la structure {siae.name} souhaite répondre en co-traitance"
+ tender_admin_url = get_admin_url_object(tender)
+ email_body = render_to_string(
+ "tenders/cocontracting_notification_email_admin_body.txt",
+ {
+ "tender_title": tender.title,
+ "tender_kind": tender.get_kind_display(),
+ "tender_admin_url": tender_admin_url,
+ "siae_name": siae.name,
+ "siae_contact_email": siae.contact_email,
+ "siae_siret": siae.siret,
+ },
+ )
+ send_mail_async(
+ email_subject=email_subject,
+ email_body=email_body,
+ recipient_list=[settings.NOTIFY_EMAIL],
+ )
+
+ # api_slack.send_message_to_channel(text=email_body, service_id=settings.SLACK_WEBHOOK_C4_SUPPORT_CHANNEL)
diff --git a/lemarche/www/tenders/urls.py b/lemarche/www/tenders/urls.py
index 87b81324d..b28c8b12f 100644
--- a/lemarche/www/tenders/urls.py
+++ b/lemarche/www/tenders/urls.py
@@ -3,6 +3,7 @@
from lemarche.www.tenders.views import (
TenderCreateMultiStepView,
+ TenderDetailCocontractingClickView,
TenderDetailContactClickStatView,
TenderDetailSurveyTransactionedView,
TenderDetailView,
@@ -32,6 +33,11 @@
path(
"
/contact-click-stat", TenderDetailContactClickStatView.as_view(), name="detail-contact-click-stat"
),
+ path(
+ "/cocontracting-click",
+ TenderDetailCocontractingClickView.as_view(),
+ name="detail-cocontracting-click",
+ ),
path(
"/sondage-transaction",
TenderDetailSurveyTransactionedView.as_view(),
diff --git a/lemarche/www/tenders/views.py b/lemarche/www/tenders/views.py
index 3738cd6e6..e46f5fb3e 100644
--- a/lemarche/www/tenders/views.py
+++ b/lemarche/www/tenders/views.py
@@ -3,7 +3,7 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.paginator import Paginator
from django.db.models import Prefetch
-from django.http import HttpResponseForbidden, HttpResponseRedirect
+from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse_lazy
from django.utils import timezone
@@ -32,6 +32,7 @@
TenderCreateStepSurveyForm,
)
from lemarche.www.tenders.tasks import ( # , send_tender_emails_to_siaes
+ notify_admin_siae_wants_cocontracting,
notify_admin_tender_created,
send_siae_interested_email_to_author,
)
@@ -403,6 +404,27 @@ def get_success_message(self, detail_contact_click_confirm):
return f"{self.object.cta_card_button_text}
Pour {self.object.cta_card_button_text.lower()}, vous devez accepter d'être mis en relation avec l'acheteur." # noqa
+class TenderDetailCocontractingClickView(LoginRequiredMixin, DetailView):
+ """
+ Endpoint to handle cocontracting button click
+ """
+
+ template_name = "tenders/_detail_cocontracting_click_confirm.html"
+ model = Tender
+
+ def get_object(self):
+ return get_object_or_404(Tender, slug=self.kwargs.get("slug"))
+
+ def post(self, request, *args, **kwargs):
+ self.object = self.get_object()
+ user = self.request.user
+
+ if settings.BITOUBI_ENV == "prod":
+ notify_admin_siae_wants_cocontracting(self.object, user.siaes.first())
+
+ return self.get(request)
+
+
class TenderSiaeListView(TenderAuthorOrAdminRequiredMixin, FormMixin, ListView):
template_name = "tenders/siae_interested_list.html"
form_class = SiaeFilterForm