Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting due amount according to current payments #8

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -370,6 +371,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 @@ -139,7 +139,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
Loading