mirror of
https://github.com/pretix/pretix.git
synced 2026-05-15 16:54:00 +00:00
Allow payment providers to supply invoice content
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.9.9 on 2016-09-06 21:31
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('pretixbase', '0036_auto_20160902_0755'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='invoice',
|
||||||
|
name='payment_provider_text',
|
||||||
|
field=models.TextField(blank=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -43,6 +43,8 @@ class Invoice(models.Model):
|
|||||||
:type introductory_text: str
|
:type introductory_text: str
|
||||||
:param additional_text: Additional text for the invoice
|
:param additional_text: Additional text for the invoice
|
||||||
:type additional_text: str
|
:type additional_text: str
|
||||||
|
:param payment_provider_text: A payment provider specific text
|
||||||
|
:type payment_provider_text: str
|
||||||
:param footer_text: A footer text, displayed smaller and centered on every page
|
:param footer_text: A footer text, displayed smaller and centered on every page
|
||||||
:type footer_text: str
|
:type footer_text: str
|
||||||
:param file: The filename of the rendered invoice
|
:param file: The filename of the rendered invoice
|
||||||
@@ -59,6 +61,7 @@ class Invoice(models.Model):
|
|||||||
locale = models.CharField(max_length=50, default='en')
|
locale = models.CharField(max_length=50, default='en')
|
||||||
introductory_text = models.TextField(blank=True)
|
introductory_text = models.TextField(blank=True)
|
||||||
additional_text = models.TextField(blank=True)
|
additional_text = models.TextField(blank=True)
|
||||||
|
payment_provider_text = models.TextField(blank=True)
|
||||||
footer_text = models.TextField(blank=True)
|
footer_text = models.TextField(blank=True)
|
||||||
file = models.FileField(null=True, blank=True, upload_to=invoice_filename)
|
file = models.FileField(null=True, blank=True, upload_to=invoice_filename)
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from django.template.loader import get_template
|
|||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from pretix.base.decimal import round_decimal
|
from pretix.base.decimal import round_decimal
|
||||||
|
from pretix.base.i18n import I18nFormField, I18nTextarea, LazyI18nString
|
||||||
from pretix.base.models import CartPosition, Event, Order, Quota
|
from pretix.base.models import CartPosition, Event, Order, Quota
|
||||||
from pretix.base.settings import SettingsSandbox
|
from pretix.base.settings import SettingsSandbox
|
||||||
from pretix.base.signals import register_payment_providers
|
from pretix.base.signals import register_payment_providers
|
||||||
@@ -134,6 +135,13 @@ class BasePaymentProvider:
|
|||||||
'above!'),
|
'above!'),
|
||||||
required=False
|
required=False
|
||||||
)),
|
)),
|
||||||
|
('_invoice_text',
|
||||||
|
I18nFormField(
|
||||||
|
label=_('Text on invoices'),
|
||||||
|
help_text=_('Will be printed just below the payment figures and above the closing text on invoices.'),
|
||||||
|
required=False,
|
||||||
|
widget=I18nTextarea,
|
||||||
|
)),
|
||||||
])
|
])
|
||||||
|
|
||||||
def settings_content_render(self, request: HttpRequest) -> str:
|
def settings_content_render(self, request: HttpRequest) -> str:
|
||||||
@@ -144,6 +152,14 @@ class BasePaymentProvider:
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def render_invoice_text(self, order: Order) -> str:
|
||||||
|
"""
|
||||||
|
This is called when an invoice for an order with this payment provider is generated.
|
||||||
|
The default implementation returns the content of the _invoice_text configuration
|
||||||
|
variable (an I18nString).
|
||||||
|
"""
|
||||||
|
return self.settings.get('_invoice_text', as_type=LazyI18nString)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def payment_form_fields(self) -> dict:
|
def payment_form_fields(self) -> dict:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ def generate_cancellation(invoice: Invoice):
|
|||||||
cancellation.date = date.today()
|
cancellation.date = date.today()
|
||||||
cancellation.refers = invoice
|
cancellation.refers = invoice
|
||||||
cancellation.invoice_no = None
|
cancellation.invoice_no = None
|
||||||
|
cancellation.payment_provider_text = ''
|
||||||
cancellation.save()
|
cancellation.save()
|
||||||
for line in invoice.lines.all():
|
for line in invoice.lines.all():
|
||||||
line.pk = None
|
line.pk = None
|
||||||
@@ -48,15 +49,24 @@ def generate_cancellation(invoice: Invoice):
|
|||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def regenerate_invoice(invoice: Invoice):
|
def regenerate_invoice(invoice: Invoice):
|
||||||
with language(invoice.locale):
|
with language(invoice.locale):
|
||||||
|
responses = register_payment_providers.send(invoice.event)
|
||||||
|
for receiver, response in responses:
|
||||||
|
provider = response(invoice.event)
|
||||||
|
if provider.identifier == invoice.order.payment_provider:
|
||||||
|
payment_provider = provider
|
||||||
|
break
|
||||||
|
|
||||||
invoice.invoice_from = invoice.event.settings.get('invoice_address_from')
|
invoice.invoice_from = invoice.event.settings.get('invoice_address_from')
|
||||||
|
|
||||||
introductory = invoice.event.settings.get('invoice_introductory_text', as_type=LazyI18nString)
|
introductory = invoice.event.settings.get('invoice_introductory_text', as_type=LazyI18nString)
|
||||||
additional = invoice.event.settings.get('invoice_additional_text', as_type=LazyI18nString)
|
additional = invoice.event.settings.get('invoice_additional_text', as_type=LazyI18nString)
|
||||||
footer = invoice.event.settings.get('invoice_footer_text', as_type=LazyI18nString)
|
footer = invoice.event.settings.get('invoice_footer_text', as_type=LazyI18nString)
|
||||||
|
payment = payment_provider.render_invoice_text(invoice.order)
|
||||||
|
|
||||||
invoice.introductory_text = str(introductory).replace('\n', '<br />')
|
invoice.introductory_text = str(introductory).replace('\n', '<br />')
|
||||||
invoice.additional_text = str(additional).replace('\n', '<br /')
|
invoice.additional_text = str(additional).replace('\n', '<br />')
|
||||||
invoice.footer_text = str(footer)
|
invoice.footer_text = str(footer)
|
||||||
|
invoice.payment_provider_text = str(payment).replace('\n', '<br />')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
addr_template = pgettext("invoice", """{i.company}
|
addr_template = pgettext("invoice", """{i.company}
|
||||||
@@ -73,13 +83,6 @@ def regenerate_invoice(invoice: Invoice):
|
|||||||
invoice.file = None
|
invoice.file = None
|
||||||
invoice.save()
|
invoice.save()
|
||||||
|
|
||||||
responses = register_payment_providers.send(invoice.event)
|
|
||||||
for receiver, response in responses:
|
|
||||||
provider = response(invoice.event)
|
|
||||||
if provider.identifier == invoice.order.payment_provider:
|
|
||||||
payment_provider = provider
|
|
||||||
break
|
|
||||||
|
|
||||||
invoice.lines.all().delete()
|
invoice.lines.all().delete()
|
||||||
for p in invoice.order.positions.all():
|
for p in invoice.order.positions.all():
|
||||||
desc = str(p.item.name)
|
desc = str(p.item.name)
|
||||||
@@ -110,16 +113,25 @@ def generate_invoice(order: Order):
|
|||||||
locale = order.locale
|
locale = order.locale
|
||||||
|
|
||||||
with language(locale):
|
with language(locale):
|
||||||
|
responses = register_payment_providers.send(order.event)
|
||||||
|
for receiver, response in responses:
|
||||||
|
provider = response(order.event)
|
||||||
|
if provider.identifier == order.payment_provider:
|
||||||
|
payment_provider = provider
|
||||||
|
break
|
||||||
|
|
||||||
i = Invoice(order=order, event=order.event)
|
i = Invoice(order=order, event=order.event)
|
||||||
i.invoice_from = order.event.settings.get('invoice_address_from')
|
i.invoice_from = order.event.settings.get('invoice_address_from')
|
||||||
|
|
||||||
introductory = i.event.settings.get('invoice_introductory_text', as_type=LazyI18nString)
|
introductory = i.event.settings.get('invoice_introductory_text', as_type=LazyI18nString)
|
||||||
additional = i.event.settings.get('invoice_additional_text', as_type=LazyI18nString)
|
additional = i.event.settings.get('invoice_additional_text', as_type=LazyI18nString)
|
||||||
footer = i.event.settings.get('invoice_footer_text', as_type=LazyI18nString)
|
footer = i.event.settings.get('invoice_footer_text', as_type=LazyI18nString)
|
||||||
|
payment = payment_provider.render_invoice_text(i.order)
|
||||||
|
|
||||||
i.introductory_text = str(introductory).replace('\n', '<br />')
|
i.introductory_text = str(introductory).replace('\n', '<br />')
|
||||||
i.additional_text = str(additional).replace('\n', '<br /')
|
i.additional_text = str(additional).replace('\n', '<br />')
|
||||||
i.footer_text = str(footer)
|
i.footer_text = str(footer)
|
||||||
|
i.payment_provider_text = str(payment).replace('\n', '<br />')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
addr_template = pgettext("invoice", """{i.company}
|
addr_template = pgettext("invoice", """{i.company}
|
||||||
@@ -137,13 +149,6 @@ def generate_invoice(order: Order):
|
|||||||
i.locale = locale
|
i.locale = locale
|
||||||
i.save()
|
i.save()
|
||||||
|
|
||||||
responses = register_payment_providers.send(order.event)
|
|
||||||
for receiver, response in responses:
|
|
||||||
provider = response(order.event)
|
|
||||||
if provider.identifier == order.payment_provider:
|
|
||||||
payment_provider = provider
|
|
||||||
break
|
|
||||||
|
|
||||||
for p in order.positions.all():
|
for p in order.positions.all():
|
||||||
desc = str(p.item.name)
|
desc = str(p.item.name)
|
||||||
if p.variation:
|
if p.variation:
|
||||||
@@ -362,6 +367,9 @@ def _invoice_generate_german(invoice, f):
|
|||||||
|
|
||||||
story.append(Spacer(1, 15 * mm))
|
story.append(Spacer(1, 15 * mm))
|
||||||
|
|
||||||
|
if invoice.payment_provider_text:
|
||||||
|
story.append(Paragraph(invoice.payment_provider_text, styles['Normal']))
|
||||||
|
|
||||||
if invoice.additional_text:
|
if invoice.additional_text:
|
||||||
story.append(Paragraph(invoice.additional_text, styles['Normal']))
|
story.append(Paragraph(invoice.additional_text, styles['Normal']))
|
||||||
story.append(Spacer(1, 15 * mm))
|
story.append(Spacer(1, 15 * mm))
|
||||||
|
|||||||
Reference in New Issue
Block a user