Do not send emails if all products are in rupture.

This commit is contained in:
Alexis M 2019-10-04 23:12:51 +02:00
parent 541e6dd354
commit 2550030bb6
2 changed files with 13 additions and 8 deletions

View file

@ -451,14 +451,15 @@ async def send_referent_emails(request, response, id):
email_subject = request.form.get("email_subject")
for referent in delivery.get_referents():
producers = delivery.get_producers_for_referent(referent)
summary = reports.summary(delivery, producers)
emails.send(
referent,
email_subject,
email_body,
copy=delivery.contact,
attachments=[(f"{config.SITE_NAME}-{date}-{referent}.xlsx", summary)],
)
if any([delivery.producers[p].has_active_products(delivery) for p in producers]):
summary = reports.summary(delivery, producers)
emails.send(
referent,
email_subject,
email_body,
copy=delivery.contact,
attachments=[(f"{config.SITE_NAME}-{date}-{referent}.xlsx", summary)],
)
response.message("Le mail à bien été envoyé")
response.redirect = f"/livraison/{id}/gérer"

View file

@ -168,6 +168,10 @@ class Producer(Base):
contact: str = ""
description: str = ""
def has_active_products(self, delivery):
products = delivery.get_products_by(self.id)
return any([not p.rupture for p in products])
@dataclass
class Product(Base):