forked from CGM_Public/pretix_original
Invoices: Hide all tax-related info if there are no taxes involved (#742)
This commit is contained in:
@@ -321,6 +321,8 @@ class ClassicInvoiceRenderer(BaseReportlabInvoiceRenderer):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def _get_story(self, doc):
|
def _get_story(self, doc):
|
||||||
|
has_taxes = any(il.tax_value for il in self.invoice.lines.all())
|
||||||
|
|
||||||
story = [
|
story = [
|
||||||
NextPageTemplate('FirstPage'),
|
NextPageTemplate('FirstPage'),
|
||||||
Paragraph(pgettext('invoice', 'Invoice')
|
Paragraph(pgettext('invoice', 'Invoice')
|
||||||
@@ -352,28 +354,48 @@ class ClassicInvoiceRenderer(BaseReportlabInvoiceRenderer):
|
|||||||
('LEFTPADDING', (0, 0), (0, -1), 0),
|
('LEFTPADDING', (0, 0), (0, -1), 0),
|
||||||
('RIGHTPADDING', (-1, 0), (-1, -1), 0),
|
('RIGHTPADDING', (-1, 0), (-1, -1), 0),
|
||||||
]
|
]
|
||||||
tdata = [(
|
if has_taxes:
|
||||||
pgettext('invoice', 'Description'),
|
tdata = [(
|
||||||
pgettext('invoice', 'Tax rate'),
|
pgettext('invoice', 'Description'),
|
||||||
pgettext('invoice', 'Net'),
|
pgettext('invoice', 'Tax rate'),
|
||||||
pgettext('invoice', 'Gross'),
|
pgettext('invoice', 'Net'),
|
||||||
)]
|
pgettext('invoice', 'Gross'),
|
||||||
|
)]
|
||||||
|
else:
|
||||||
|
tdata = [(
|
||||||
|
pgettext('invoice', 'Description'),
|
||||||
|
pgettext('invoice', 'Amount'),
|
||||||
|
)]
|
||||||
|
|
||||||
total = Decimal('0.00')
|
total = Decimal('0.00')
|
||||||
for line in self.invoice.lines.all():
|
for line in self.invoice.lines.all():
|
||||||
tdata.append((
|
if has_taxes:
|
||||||
Paragraph(line.description, self.stylesheet['Normal']),
|
tdata.append((
|
||||||
localize(line.tax_rate) + " %",
|
Paragraph(line.description, self.stylesheet['Normal']),
|
||||||
localize(line.net_value) + " " + self.invoice.event.currency,
|
localize(line.tax_rate) + " %",
|
||||||
localize(line.gross_value) + " " + self.invoice.event.currency,
|
localize(line.net_value) + " " + self.invoice.event.currency,
|
||||||
))
|
localize(line.gross_value) + " " + self.invoice.event.currency,
|
||||||
|
))
|
||||||
|
else:
|
||||||
|
tdata.append((
|
||||||
|
Paragraph(line.description, self.stylesheet['Normal']),
|
||||||
|
localize(line.gross_value) + " " + self.invoice.event.currency,
|
||||||
|
))
|
||||||
taxvalue_map[line.tax_rate, line.tax_name] += line.tax_value
|
taxvalue_map[line.tax_rate, line.tax_name] += line.tax_value
|
||||||
grossvalue_map[line.tax_rate, line.tax_name] += line.gross_value
|
grossvalue_map[line.tax_rate, line.tax_name] += line.gross_value
|
||||||
total += line.gross_value
|
total += line.gross_value
|
||||||
|
|
||||||
tdata.append([
|
if has_taxes:
|
||||||
pgettext('invoice', 'Invoice total'), '', '', localize(total) + " " + self.invoice.event.currency
|
tdata.append([
|
||||||
])
|
pgettext('invoice', 'Invoice total'), '', '', localize(total) + " " + self.invoice.event.currency
|
||||||
colwidths = [a * doc.width for a in (.55, .15, .15, .15)]
|
])
|
||||||
|
colwidths = [a * doc.width for a in (.55, .15, .15, .15)]
|
||||||
|
else:
|
||||||
|
tdata.append([
|
||||||
|
pgettext('invoice', 'Invoice total'), localize(total) + " " + self.invoice.event.currency
|
||||||
|
])
|
||||||
|
colwidths = [a * doc.width for a in (.70, .30)]
|
||||||
|
|
||||||
table = Table(tdata, colWidths=colwidths, repeatRows=1)
|
table = Table(tdata, colWidths=colwidths, repeatRows=1)
|
||||||
table.setStyle(TableStyle(tstyledata))
|
table.setStyle(TableStyle(tstyledata))
|
||||||
story.append(table)
|
story.append(table)
|
||||||
@@ -422,7 +444,7 @@ class ClassicInvoiceRenderer(BaseReportlabInvoiceRenderer):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
return localize(val) + ' ' + self.invoice.foreign_currency_display
|
return localize(val) + ' ' + self.invoice.foreign_currency_display
|
||||||
|
|
||||||
if len(tdata) > 1:
|
if len(tdata) > 1 and has_taxes:
|
||||||
colwidths = [a * doc.width for a in (.25, .15, .15, .15, .3)]
|
colwidths = [a * doc.width for a in (.25, .15, .15, .15, .3)]
|
||||||
table = Table(tdata, colWidths=colwidths, repeatRows=2, hAlign=TA_LEFT)
|
table = Table(tdata, colWidths=colwidths, repeatRows=2, hAlign=TA_LEFT)
|
||||||
table.setStyle(TableStyle(tstyledata))
|
table.setStyle(TableStyle(tstyledata))
|
||||||
|
|||||||
Reference in New Issue
Block a user