membershipworks: More thoroughly check if events are ready for an invoice
All checks were successful
Ruff / ruff (push) Successful in 37s
Test / test (push) Successful in 5m29s

This commit is contained in:
Adam Goldsmith 2024-05-02 23:53:48 -04:00
parent 0f30358357
commit 31cc5312ad
3 changed files with 14 additions and 2 deletions

View File

@ -25,7 +25,7 @@ class EventInvoiceForm(forms.Form):
if hasattr(self.event, "invoice") is not None:
raise forms.ValidationError("An invoice was already created!")
if self.event.total_due_to_instructor is None:
if not self.event.ready_for_invoice:
raise forms.ValidationError(
"Event missing required information to generate invoice"
)

View File

@ -563,6 +563,18 @@ class EventExt(Event):
return self.instructor.member == member
return False
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
)
class Meta:
verbose_name = "event"
ordering = ["-start"]

View File

@ -27,7 +27,7 @@
<a class="btn btn-primary"
href="{% url 'membershipworks:event-invoice-pdf' event.invoice.pk %}">View PDF</a>
</div>
{% elif event.total_due_to_instructor is None %}
{% elif not event.ready_for_invoice %}
<p class="card-text text-center">
This event is missing required information to generate an invoice. Please contact us at <a href="mailto:info@claremontmakerspace.org">info@claremontmakerspace.org</a>.
</p>