Skip to content

Commit

Permalink
Order change: Do not set invoice_dirty if invoicing is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Nov 30, 2023
1 parent fbf362a commit bd14be4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/pretix/base/services/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -2620,7 +2620,7 @@ def _reissue_invoice(self):
i = self.order.invoices.filter(is_cancellation=False).last()
if self.reissue_invoice and self._invoice_dirty:
order_now_qualified = invoice_qualified(self.order)
invoice_should_be_generated = (
invoice_should_be_generated_now = (
self.event.settings.invoice_generate == "True" or (
self.event.settings.invoice_generate == "paid" and
self.open_payment is not None and
Expand All @@ -2635,13 +2635,16 @@ def _reissue_invoice(self):
not i.canceled
)
)
invoice_should_be_generated_later = not invoice_should_be_generated_now and (
self.event.settings.invoice_generate in ("True", "paid")
)

if order_now_qualified:
if invoice_should_be_generated:
if invoice_should_be_generated_now:
if i and not i.canceled:
self._invoices.append(generate_cancellation(i))
self._invoices.append(generate_invoice(self.order))
else:
elif invoice_should_be_generated_later:
self.order.invoice_dirty = True
self.order.save(update_fields=["invoice_dirty"])
else:
Expand Down
14 changes: 14 additions & 0 deletions src/tests/base/test_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,20 @@ def test_reissue_invoice_paid_only_after_payment(self):
).confirm()
assert self.order.invoices.count() == 3

@classscope(attr='o')
def test_reissue_invoice_paid_only_after_payment_only_if_enabled(self):
self.event.settings.invoice_generate = "False"
assert self.order.invoices.count() == 0
self.ocm.add_position(self.ticket, None, Decimal('2.00'))
self.ocm.commit()
assert self.order.invoices.count() == 0
self.order.refresh_from_db()
assert not self.order.invoice_dirty
self.order.payments.create(
provider='manual', amount=self.order.total
).confirm()
assert self.order.invoices.count() == 0

@classscope(attr='o')
def test_reissue_invoice_paid_stays_paid(self):
self.event.settings.invoice_generate = "paid"
Expand Down

0 comments on commit bd14be4

Please sign in to comment.