Skip to content

Commit

Permalink
Allow setting due amount according to current payments (#8)
Browse files Browse the repository at this point in the history
* Allow setting due amount according to current payments

* No negative amounts
  • Loading branch information
raphaelm authored Feb 6, 2025
1 parent 37de058 commit 49f72cb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions pretix_zugferd/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from drafthorse.models.tradelines import LineItem
from drafthorse.pdf import attach_xml
from pretix.base.invoice import ClassicInvoiceRenderer, Modern1Renderer
from pretix.base.models import Order
from pretix.base.models.tax import EU_COUNTRIES
from reportlab.lib.units import mm
from reportlab.pdfgen.canvas import Canvas
Expand Down Expand Up @@ -380,6 +381,19 @@ def _zugferd_generate_document(self, invoice):
doc.trade.settlement.monetary_summation.tax_total = (taxtotal, cc)
doc.trade.settlement.monetary_summation.grand_total = total
doc.trade.settlement.monetary_summation.due_amount = total

if not self.invoice.is_cancellation:
payment_refund_sum = self.invoice.order.payment_refund_sum
if payment_refund_sum and (
self.invoice.event.settings.invoice_show_payments
or self.invoice.order.status == Order.STATUS_PAID
):
doc.trade.settlement.monetary_summation.prepaid_total = min(
payment_refund_sum, total
)
doc.trade.settlement.monetary_summation.due_amount = min(
total - payment_refund_sum, Decimal("0.00")
)
return doc

def _on_first_page(self, canvas: Canvas, doc):
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def order(event, organizer, item):
sales_channel=event.organizer.sales_channels.get(identifier="web"),
datetime=datetime(2024, 12, 1, 10, 0, 0, tzinfo=UTC),
expires=datetime(2024, 12, 10, 10, 0, 0, tzinfo=UTC),
total=Decimal("100.00"),
total=Decimal("23.00"),
locale="en",
)
OrderPosition.objects.create(
Expand Down
3 changes: 2 additions & 1 deletion tests/results/paid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ Attendee: Peter</ram:Description>
<ram:TaxBasisTotalAmount>19.33</ram:TaxBasisTotalAmount>
<ram:TaxTotalAmount currencyID="EUR">3.67</ram:TaxTotalAmount>
<ram:GrandTotalAmount>23.00</ram:GrandTotalAmount>
<ram:DuePayableAmount>23.00</ram:DuePayableAmount>
<ram:TotalPrepaidAmount>23.00</ram:TotalPrepaidAmount>
<ram:DuePayableAmount>0.00</ram:DuePayableAmount>
</ram:SpecifiedTradeSettlementHeaderMonetarySummation>
</ram:ApplicableHeaderTradeSettlement>
</rsm:SupplyChainTradeTransaction>
Expand Down

0 comments on commit 49f72cb

Please sign in to comment.