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,6 +451,7 @@ 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)
if any([delivery.producers[p].has_active_products(delivery) for p in producers]):
summary = reports.summary(delivery, producers)
emails.send(
referent,

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):