Skip to content

Commit

Permalink
clean tasks to save the log in the tenders only when partners count i…
Browse files Browse the repository at this point in the history
…s postive
  • Loading branch information
madjid-asa committed Feb 14, 2024
1 parent 39a37fc commit 9cab0e1
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lemarche/www/tenders/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,22 @@ def send_tender_emails_to_partners(tender: Tender):
All corresponding partners (PartnerShareTender) will be contacted
"""
partners = PartnerShareTender.objects.filter_by_tender(tender)
email_subject = f"{tender.get_kind_display()} : {tender.title} ({tender.author.company_name})"

for partner in partners:
send_tender_email_to_partner(email_subject, tender, partner)

# log email batch
log_item = {
"action": "email_partners_matched",
"email_subject": email_subject,
"email_count": partners.count(),
"email_timestamp": timezone.now().isoformat(),
}
tender.logs.append(log_item)
tender.save()
partners_count = partners.count()

if partners_count > 0:
email_subject = f"{tender.get_kind_display()} : {tender.title} ({tender.author.company_name})"
for partner in partners:
send_tender_email_to_partner(email_subject, tender, partner)

# log email batch
log_item = {
"action": "email_partners_matched",
"email_subject": email_subject,
"email_count": partners_count,
"email_timestamp": timezone.now().isoformat(),
}
tender.logs.append(log_item)
tender.save()


def send_tender_email_to_partner(email_subject: str, tender: Tender, partner: PartnerShareTender):
Expand Down

0 comments on commit 9cab0e1

Please sign in to comment.