From 59edb355f80b9ea232834d5fd37d80edc6bbb98f Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 25 Jul 2022 18:24:00 +0200 Subject: [PATCH] Invoice renderer: Print gift card amount even on paid orders if partial payments should be printed (#2734) --- src/pretix/base/invoice.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/pretix/base/invoice.py b/src/pretix/base/invoice.py index 959010626c..65e25458a1 100644 --- a/src/pretix/base/invoice.py +++ b/src/pretix/base/invoice.py @@ -28,6 +28,7 @@ from typing import Tuple import bleach import vat_moss.exchange_rates from django.contrib.staticfiles import finders +from django.db.models import Sum from django.dispatch import receiver from django.utils.formats import date_format, localize from django.utils.translation import ( @@ -47,7 +48,7 @@ from reportlab.platypus import ( ) from pretix.base.decimal import round_decimal -from pretix.base.models import Event, Invoice, Order +from pretix.base.models import Event, Invoice, Order, OrderPayment from pretix.base.signals import register_invoice_renderers from pretix.base.templatetags.money import money_filter from pretix.helpers.reportlab import ThumbnailingImageReader @@ -589,15 +590,33 @@ class ClassicInvoiceRenderer(BaseReportlabInvoiceRenderer): ]) colwidths = [a * doc.width for a in (.65, .05, .30)] - if self.invoice.event.settings.invoice_show_payments and not self.invoice.is_cancellation and \ - self.invoice.order.status == Order.STATUS_PENDING: - pending_sum = self.invoice.order.pending_sum - if pending_sum != total: - tdata.append([pgettext('invoice', 'Received payments')] + (['', '', ''] if has_taxes else ['']) + [ - money_filter(pending_sum - total, self.invoice.event.currency) + if self.invoice.event.settings.invoice_show_payments and not self.invoice.is_cancellation: + if self.invoice.order.status == Order.STATUS_PENDING: + pending_sum = self.invoice.order.pending_sum + if pending_sum != total: + tdata.append([pgettext('invoice', 'Received payments')] + (['', '', ''] if has_taxes else ['']) + [ + money_filter(pending_sum - total, self.invoice.event.currency) + ]) + tdata.append([pgettext('invoice', 'Outstanding payments')] + (['', '', ''] if has_taxes else ['']) + [ + money_filter(pending_sum, self.invoice.event.currency) + ]) + tstyledata += [ + ('FONTNAME', (0, len(tdata) - 3), (-1, len(tdata) - 3), self.font_bold), + ] + elif self.invoice.order.payments.filter( + state__in=(OrderPayment.PAYMENT_STATE_CONFIRMED, OrderPayment.PAYMENT_STATE_REFUNDED), provider='giftcard' + ).exists(): + giftcard_sum = self.invoice.order.payments.filter( + state__in=(OrderPayment.PAYMENT_STATE_CONFIRMED, OrderPayment.PAYMENT_STATE_REFUNDED), + provider='giftcard' + ).aggregate( + s=Sum('amount') + )['s'] or Decimal('0.00') + tdata.append([pgettext('invoice', 'Paid by gift card')] + (['', '', ''] if has_taxes else ['']) + [ + money_filter(giftcard_sum, self.invoice.event.currency) ]) - tdata.append([pgettext('invoice', 'Outstanding payments')] + (['', '', ''] if has_taxes else ['']) + [ - money_filter(pending_sum, self.invoice.event.currency) + tdata.append([pgettext('invoice', 'Remaining amount')] + (['', '', ''] if has_taxes else ['']) + [ + money_filter(total - giftcard_sum, self.invoice.event.currency) ]) tstyledata += [ ('FONTNAME', (0, len(tdata) - 3), (-1, len(tdata) - 3), self.font_bold),