-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Ajout d'un attribut pour filtrer l'envoi des besoins d'achat #1446
Changes from 12 commits
987db15
4154b8a
33532e8
9f7ab8b
34af7ac
dc15ed9
8d66675
fd6cdee
4d6a3a6
1553afe
6680db0
193200f
4f6e2aa
9a0dc36
f89e2e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,55 @@ | ||||||||||
document.addEventListener('DOMContentLoaded', function () { | ||||||||||
const modal = document.getElementById('tender-send-confirmation-modal'); | ||||||||||
const confirmBtn = document.getElementById('submit-button'); | ||||||||||
const cancelBtn = document.getElementById('cancel-button'); | ||||||||||
|
||||||||||
function openModal(recipient, title) { | ||||||||||
const messageElement = document.getElementById('tender-send-message'); | ||||||||||
|
||||||||||
// Set an attribute 'name' depending on the recipient | ||||||||||
if (recipient === 'siaes') { | ||||||||||
messageElement.textContent = "Le besoin « " + title + " » sera envoyé aux structures."; | ||||||||||
confirmBtn.setAttribute('name', '_validate_send_to_siaes'); | ||||||||||
} else if (recipient === 'partners') { | ||||||||||
messageElement.textContent = "Le besoin « " + title + " » sera envoyé aux partenaires."; | ||||||||||
confirmBtn.setAttribute('name', '_validate_send_to_commercial_partners'); | ||||||||||
} | ||||||||||
modal.style.display = 'block'; | ||||||||||
} | ||||||||||
|
||||||||||
// data-recipent attribute determines the recipient of the tender | ||||||||||
const buttons = document.querySelectorAll('input[data-recipient]'); | ||||||||||
buttons.forEach(function(button) { | ||||||||||
button.addEventListener('click', function(e) { | ||||||||||
e.preventDefault(); // Prevent instant form submission | ||||||||||
const recipient = button.getAttribute('data-recipient'); | ||||||||||
const title = button.getAttribute('data-title'); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Tu utilise généralement les getAttribute pour les attributs non-standards, mais pour les data-* tu peux utiliser dataset |
||||||||||
openModal(recipient, title); | ||||||||||
}); | ||||||||||
}); | ||||||||||
|
||||||||||
function closeModal() { | ||||||||||
modal.style.display = 'none'; | ||||||||||
} | ||||||||||
|
||||||||||
// Two different ways to close the modal: | ||||||||||
// click on the cancel button | ||||||||||
cancelBtn.addEventListener('click', function(e) { | ||||||||||
e.preventDefault(); // Prevent page from scrolling up | ||||||||||
closeModal(); | ||||||||||
}); | ||||||||||
|
||||||||||
// click outside the modal | ||||||||||
window.addEventListener('click', function (e) { | ||||||||||
if (e.target === modal) { | ||||||||||
closeModal(); | ||||||||||
} | ||||||||||
}); | ||||||||||
|
||||||||||
// Action confirmation | ||||||||||
confirmBtn.addEventListener('click', function () { | ||||||||||
if (formToSubmit) { | ||||||||||
formToSubmit.submit(); | ||||||||||
} | ||||||||||
}); | ||||||||||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -526,6 +526,9 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin): | |
|
||
change_form_template = "tenders/admin_change_form.html" | ||
|
||
class Media: | ||
js = ["/static/js/admin_tender_confirmation.js"] | ||
|
||
def get_queryset(self, request): | ||
qs = super().get_queryset(request) | ||
qs = qs.select_related("author") | ||
|
@@ -783,14 +786,25 @@ def response_change(self, request, obj: Tender): | |
obj.set_siae_found_list() | ||
self.message_user(request, "Les structures concernées ont été mises à jour.") | ||
return HttpResponseRedirect("./#structures") # redirect to structures sections | ||
if request.POST.get("_validate_tender"): | ||
if request.POST.get("_validate_send_to_siaes"): | ||
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_contact_list(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(".") | ||
if request.POST.get("_validate_send_to_commercial_partners"): | ||
obj.set_validated() | ||
obj.send_to_commercial_partners_only = True | ||
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_contact_list(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 :)") | ||
obj.save() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pas besoin du |
||
return HttpResponseRedirect(".") | ||
elif request.POST.get("_restart_tender"): | ||
restart_send_tender_task(tender=obj) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 4.2.15 on 2024-09-27 12:50 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("tenders", "0091_tender_is_followed_by_us_tender_is_reserved_tender_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="tender", | ||
name="send_to_commercial_partners_only", | ||
field=models.BooleanField(default=False, verbose_name="Envoyer uniquement aux partenaires externes"), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -87,6 +87,7 @@ def validated_sent_batch(self): | |||||
& Q(siae_detail_contact_click_count_annotated__lte=F("limit_nb_siae_interested")) | ||||||
& ~Q(siae_count_annotated=F("siae_email_send_count_annotated")) | ||||||
& Q(last_sent_at__lt=yesterday) | ||||||
& Q(send_to_commercial_partners_only=False) | ||||||
) | ||||||
) | ||||||
|
||||||
|
@@ -632,6 +633,9 @@ class Tender(models.Model): | |||||
) # could become foreign key | ||||||
# Admin specific for tenders | ||||||
is_reserved_tender = models.BooleanField("Appel d'offre reservé", null=True) | ||||||
send_to_commercial_partners_only = models.BooleanField( | ||||||
"Envoyer uniquement aux partenaires externes", default=False | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Préciser commerciaux pour ne pas confondre avec les partenaires externes (types facilitateurs ou autre) |
||||||
) | ||||||
|
||||||
# partner data | ||||||
partner_approch_id = models.IntegerField("Partenaire APProch : ID", blank=True, null=True) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'aurais peut-être précisé ici: "Le besoin '[titre]' sera envoyé uniquement aux prestataires commerciaux.". Qu'en penses tu ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merci pour ta remarque @SebastienReuiller, effectivement ce serait plus clair comme ça !