From fd26e2b17ddb0692bf67df8e6458ac0477f1719e Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 25 Nov 2024 13:37:50 -0500 Subject: [PATCH] membershipworks: Provide details when an event is not ready for invoice --- membershipworks/models.py | 28 ++++++++++++------- .../membershipworks/event_detail.dj.html | 8 ++++++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/membershipworks/models.py b/membershipworks/models.py index 2e601ac..eccdcb5 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -613,18 +613,26 @@ class EventExt(Event): return self.instructor.member == member return False + @property + def missing_for_invoice(self) -> list[str]: + reasons = { + "Missing instructor": self.instructor is None, + "Instructor not linked to a member": ( + self.instructor is not None and self.instructor.member is None + ), + "Missing materials fee": self.materials_fee is None, + "Materials fee is not 0 and materials_fee_included_in_price not defined": ( + self.materials_fee != 0 and self.materials_fee_included_in_price is None + ), + "total_due_to_instructor is None (this can have several causes)": ( + self.total_due_to_instructor is None + ), + } + return [k for k, v in reasons.items() if v] + @property def ready_for_invoice(self) -> bool: - return ( - self.instructor is not None - and self.instructor.member is not None - and self.materials_fee is not None - and ( - self.materials_fee_included_in_price is not None - or self.materials_fee == 0 - ) - and self.total_due_to_instructor is not None - ) + return len(self.missing_for_invoice) == 0 if TYPE_CHECKING: diff --git a/membershipworks/templates/membershipworks/event_detail.dj.html b/membershipworks/templates/membershipworks/event_detail.dj.html index dab8429..69f35b5 100644 --- a/membershipworks/templates/membershipworks/event_detail.dj.html +++ b/membershipworks/templates/membershipworks/event_detail.dj.html @@ -38,6 +38,14 @@ {% elif not event.ready_for_invoice %}

This event is missing required information to generate an invoice. Please contact us at info@claremontmakerspace.org. + {% if perms.membershipworks.view_event %} +

+
Issues:
+ +
+ {% endif %}

{% elif user_is_instructor %}