mirror of
https://github.com/pretix/pretix.git
synced 2026-08-19 12:16:26 +00:00
Fix previous changes, add describe function
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#
|
||||
from typing import Optional
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django_countries.fields import Country
|
||||
|
||||
from pretix.base.models import Invoice, InvoiceAddress
|
||||
@@ -106,6 +107,22 @@ class TransmissionType:
|
||||
def transmission_info_to_form_data(self, transmission_info: dict) -> dict:
|
||||
return transmission_info
|
||||
|
||||
def describe_info(self, transmission_info: dict, country: Country, is_business: bool):
|
||||
form_data = self.transmission_info_to_form_data(transmission_info)
|
||||
data = []
|
||||
visible_field_keys = self.invoice_address_form_fields_visible(country, is_business)
|
||||
for k, f in self.invoice_address_form_fields.items():
|
||||
if k not in visible_field_keys:
|
||||
continue
|
||||
v = form_data.get(k)
|
||||
if v is True:
|
||||
v = _("Yes")
|
||||
elif v is False:
|
||||
v = _("No")
|
||||
if v:
|
||||
data.append((f.label, v))
|
||||
return data
|
||||
|
||||
def pdf_watermark(self) -> Optional[str]:
|
||||
"""
|
||||
Return a watermark that should be rendered across the PDF file.
|
||||
|
||||
@@ -3526,40 +3526,12 @@ class InvoiceAddress(models.Model):
|
||||
})
|
||||
return d
|
||||
|
||||
def describe_transmission(self, event=None):
|
||||
# we only need an explicit event if the order is not yet created and we do not want to show unnecessary data to customers
|
||||
def describe_transmission(self):
|
||||
from pretix.base.invoicing.transmission import transmission_types
|
||||
data = []
|
||||
|
||||
t, m = transmission_types.get(identifier=self.transmission_type)
|
||||
|
||||
d_event = self.order.event if self.order else event
|
||||
# reusing hack from questions.py for default transmission -- this should at least be fast
|
||||
if d_event:
|
||||
if (
|
||||
t.identifier == "email" and
|
||||
m in ("transmission_email_other", "transmission_email_address") and
|
||||
(
|
||||
d_event.settings.invoice_generate == "False" or
|
||||
not d_event.settings.invoice_email_attachment
|
||||
)
|
||||
):
|
||||
return data
|
||||
|
||||
# we also don't show transmission data if we never showed the corresponding form fields
|
||||
if not t.invoice_address_form_fields_visible(country=self.country, is_business=self.is_business):
|
||||
return data
|
||||
|
||||
t, __ = transmission_types.get(identifier=self.transmission_type)
|
||||
data.append((_("Transmission type"), t.public_name))
|
||||
form_data = t.transmission_info_to_form_data(self.transmission_info or {})
|
||||
for k, f in t.invoice_address_form_fields.items():
|
||||
v = form_data.get(k)
|
||||
if v is True:
|
||||
v = _("Yes")
|
||||
elif v is False:
|
||||
v = _("No")
|
||||
if v:
|
||||
data.append((f.label, v))
|
||||
data += t.describe_info(self.transmission_info, self.country, self.is_business)
|
||||
return data
|
||||
|
||||
|
||||
|
||||
@@ -1545,8 +1545,6 @@ class ConfirmStep(CartMixin, AsyncAction, TemplateFlowStep):
|
||||
ctx['invoice_address_asked'] = self.address_asked
|
||||
ctx['customer'] = self.cart_customer
|
||||
|
||||
ctx['transmission_fields'] = self.invoice_address.describe_transmission(self.event)
|
||||
|
||||
self.cart_session['shown_total'] = str(ctx['cart']['total'])
|
||||
|
||||
email = self.cart_session.get('contact_form_data', {}).get('email')
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
<dt>{% trans "Internal reference" %}</dt>
|
||||
<dd>{{ addr.internal_reference }}</dd>
|
||||
{% endif %}
|
||||
{% for k, v in transmission_fields %}
|
||||
{% for k, v in addr.describe_transmission %}
|
||||
<dt>{{ k }}</dt>
|
||||
<dd>{{ v }}</dd>
|
||||
{% endfor %}
|
||||
|
||||
Reference in New Issue
Block a user