forked from CGM_Public/pretix_original
Pluggable invoice transmission methods (#5020)
* Flexible invoice transmission
* UI work
* Add peppol and output
* API support
* Profile integration
* Simplify form for individuals
* Remove sent_to_customer usage
* more steps
* Revert "Bank transfer: Allow to send the invoice direclty to the accounting department (#2975)"
This reverts commit cea6c340be.
* minor fixes
* Fixes after rebase
* update stati
* Backend view
* Transmit and show status
* status, retransmission
* API retransmission
* More fields
* API docs
* Plugin docs
* Update migration
* Add missing license headers
* Remove dead code, fix current tests
* Run isort
* Update regex
* Rebase migration
* Fix migration
* Add tests, fix bugs
* Rebase migration
* Apply suggestion from @luelista
Co-authored-by: luelista <weller@rami.io>
* Apply suggestion from @luelista
Co-authored-by: luelista <weller@rami.io>
* Apply suggestion from @luelista
Co-authored-by: luelista <weller@rami.io>
* Apply suggestion from @luelista
Co-authored-by: luelista <weller@rami.io>
* Apply suggestion from @luelista
Co-authored-by: luelista <weller@rami.io>
* Make migration reversible
* Add TransmissionType.enforce_transmission
* Fix registries API usage after rebase
* Remove code I forgot to delete
* Update transmission status display depending on type
* Add testmode_supported
* Update src/pretix/static/pretixbase/js/addressform.js
Co-authored-by: luelista <weller@rami.io>
* Update src/pretix/static/pretixbase/js/addressform.js
Co-authored-by: luelista <weller@rami.io>
* Update src/pretix/static/pretixbase/js/addressform.js
Co-authored-by: luelista <weller@rami.io>
* New mechanism for non-required invoice forms
* Update src/pretix/base/invoicing/transmission.py
Co-authored-by: luelista <weller@rami.io>
* Declare testmode_supported for email
* Make transmission_email_other an implementation detail
* Fix failing tests and add new ones
* Update src/pretix/base/services/invoices.py
Co-authored-by: luelista <weller@rami.io>
* Add emails to email history
* Fix comma error
* More generic default email text
* Cleanup
* Remove "email invoices" button and refine logic
* Rebase migration
* Fix edge case
---------
Co-authored-by: luelista <weller@rami.io>
This commit is contained in:
@@ -42,7 +42,7 @@ from django.db.models.functions import Cast
|
||||
from django.utils import timezone
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import pgettext
|
||||
from django.utils.translation import gettext_lazy as _, pgettext
|
||||
from django_scopes import ScopedManager
|
||||
|
||||
from pretix.base.settings import COUNTRIES_WITH_STATE_IN_ADDRESS
|
||||
@@ -110,6 +110,21 @@ class Invoice(models.Model):
|
||||
:param file: The filename of the rendered invoice
|
||||
:type file: File
|
||||
"""
|
||||
TRANSMISSION_STATUS_PENDING = "pending"
|
||||
TRANSMISSION_STATUS_INFLIGHT = "inflight"
|
||||
TRANSMISSION_STATUS_COMPLETED = "completed"
|
||||
TRANSMISSION_STATUS_FAILED = "failed"
|
||||
TRANSMISSION_STATUS_UNKNOWN = "unknown"
|
||||
TRANSMISSION_STATUS_TESTMODE_IGNORED = "testmode_ignored"
|
||||
TRANSMISSION_STATUS_CHOICES = (
|
||||
(TRANSMISSION_STATUS_PENDING, _("pending transmission")),
|
||||
(TRANSMISSION_STATUS_INFLIGHT, _("currently being transmitted")),
|
||||
(TRANSMISSION_STATUS_COMPLETED, _("transmitted")),
|
||||
(TRANSMISSION_STATUS_FAILED, _("failed")),
|
||||
(TRANSMISSION_STATUS_UNKNOWN, _("unknown")),
|
||||
(TRANSMISSION_STATUS_TESTMODE_IGNORED, _("not transmitted due to test mode")),
|
||||
)
|
||||
|
||||
order = models.ForeignKey('Order', related_name='invoices', db_index=True, on_delete=models.CASCADE)
|
||||
organizer = models.ForeignKey('Organizer', related_name='invoices', db_index=True, on_delete=models.PROTECT)
|
||||
event = models.ForeignKey('Event', related_name='invoices', db_index=True, on_delete=models.CASCADE)
|
||||
@@ -131,6 +146,7 @@ class Invoice(models.Model):
|
||||
|
||||
invoice_to = models.TextField()
|
||||
invoice_to_company = models.TextField(null=True)
|
||||
invoice_to_is_business = models.BooleanField(null=True)
|
||||
invoice_to_name = models.TextField(null=True)
|
||||
invoice_to_street = models.TextField(null=True)
|
||||
invoice_to_zipcode = models.CharField(max_length=190, null=True)
|
||||
@@ -139,9 +155,11 @@ class Invoice(models.Model):
|
||||
invoice_to_country = FastCountryField(null=True)
|
||||
invoice_to_vat_id = models.TextField(null=True)
|
||||
invoice_to_beneficiary = models.TextField(null=True)
|
||||
invoice_to_transmission_info = models.JSONField(null=True, blank=True)
|
||||
internal_reference = models.TextField(blank=True)
|
||||
custom_field = models.CharField(max_length=255, null=True)
|
||||
|
||||
created = models.DateTimeField(auto_now_add=True, null=True) # null for backwards compatibility
|
||||
date = models.DateField(default=today)
|
||||
locale = models.CharField(max_length=50, default='en')
|
||||
introductory_text = models.TextField(blank=True)
|
||||
@@ -158,14 +176,28 @@ class Invoice(models.Model):
|
||||
|
||||
shredded = models.BooleanField(default=False)
|
||||
|
||||
# The field sent_to_organizer records whether this invocie was already sent to the organizer by a configured
|
||||
# The field sent_to_organizer records whether this invoice was already sent to the organizer by a configured
|
||||
# mechanism such as email.
|
||||
# NULL: The cronjob that handles sending did not yet run.
|
||||
# True: The invoice was sent.
|
||||
# False: The invoice wasn't sent and never will, because sending was not configured at the time of the check.
|
||||
sent_to_organizer = models.BooleanField(null=True, blank=True)
|
||||
|
||||
sent_to_customer = models.DateTimeField(null=True, blank=True)
|
||||
transmission_type = models.CharField(
|
||||
max_length=255,
|
||||
default="email",
|
||||
)
|
||||
transmission_provider = models.CharField(
|
||||
max_length=255,
|
||||
null=True, blank=True,
|
||||
)
|
||||
transmission_status = models.CharField(
|
||||
max_length=255,
|
||||
choices=TRANSMISSION_STATUS_CHOICES,
|
||||
default=TRANSMISSION_STATUS_UNKNOWN,
|
||||
)
|
||||
transmission_date = models.DateTimeField(null=True, blank=True)
|
||||
transmission_info = models.JSONField(null=True, blank=True)
|
||||
|
||||
file = models.FileField(null=True, blank=True, upload_to=invoice_filename, max_length=255)
|
||||
|
||||
@@ -323,6 +355,19 @@ class Invoice(models.Model):
|
||||
def __str__(self):
|
||||
return self.full_invoice_no
|
||||
|
||||
@property
|
||||
def regenerate_allowed(self):
|
||||
return self.transmission_status in (
|
||||
Invoice.TRANSMISSION_STATUS_UNKNOWN,
|
||||
Invoice.TRANSMISSION_STATUS_PENDING,
|
||||
Invoice.TRANSMISSION_STATUS_FAILED,
|
||||
) and self.event.settings.invoice_regenerate_allowed
|
||||
|
||||
@property
|
||||
def transmission_type_instance(self):
|
||||
from pretix.base.invoicing.transmission import transmission_types
|
||||
return transmission_types.get(identifier=self.transmission_type)[0]
|
||||
|
||||
|
||||
class InvoiceLine(models.Model):
|
||||
"""
|
||||
|
||||
@@ -1939,6 +1939,7 @@ class OrderPayment(models.Model):
|
||||
ignore_date=False, lock=True, payment_refund_sum=0, allow_generate_invoice=True):
|
||||
from pretix.base.services.invoices import (
|
||||
generate_cancellation, generate_invoice, invoice_qualified,
|
||||
invoice_transmission_separately, transmit_invoice,
|
||||
)
|
||||
from pretix.base.services.locking import LOCK_TRUST_WINDOW
|
||||
|
||||
@@ -1969,13 +1970,19 @@ class OrderPayment(models.Model):
|
||||
trigger_pdf=not send_mail or not self.order.event.settings.invoice_email_attachment
|
||||
)
|
||||
|
||||
transmit_invoice_task = invoice_transmission_separately(invoice)
|
||||
transmit_invoice_mail = not transmit_invoice_task and self.order.event.settings.invoice_email_attachment and self.order.email
|
||||
|
||||
if send_mail and self.order.sales_channel.identifier in self.order.event.settings.mail_sales_channel_placed_paid:
|
||||
self._send_paid_mail(invoice, user, mail_text)
|
||||
self._send_paid_mail(invoice if transmit_invoice_mail else None, user, mail_text)
|
||||
if self.order.event.settings.mail_send_order_paid_attendee:
|
||||
for p in self.order.positions.all():
|
||||
if p.addon_to_id is None and p.attendee_email and p.attendee_email != self.order.email:
|
||||
self._send_paid_mail_attendee(p, user)
|
||||
|
||||
if invoice and not transmit_invoice_mail:
|
||||
transmit_invoice.apply_async(args=(self.order.event_id, invoice.pk, False))
|
||||
|
||||
def _send_paid_mail_attendee(self, position, user):
|
||||
from pretix.base.services.mail import SendMailException
|
||||
|
||||
@@ -2005,7 +2012,7 @@ class OrderPayment(models.Model):
|
||||
self.order.send_mail(
|
||||
email_subject, email_template, email_context,
|
||||
'pretix.event.order.email.order_paid', user,
|
||||
invoices=[invoice] if invoice and self.order.event.settings.invoice_email_attachment else [],
|
||||
invoices=[invoice] if invoice else [],
|
||||
attach_tickets=True,
|
||||
attach_ical=self.order.event.settings.mail_attach_ical
|
||||
)
|
||||
@@ -3293,6 +3300,9 @@ class InvoiceAddress(models.Model):
|
||||
blank=True
|
||||
)
|
||||
|
||||
transmission_type = models.CharField(max_length=255, default="email")
|
||||
transmission_info = models.JSONField(null=True, blank=True)
|
||||
|
||||
objects = ScopedManager(organizer='order__event__organizer')
|
||||
profiles = ScopedManager(organizer='customer__organizer')
|
||||
|
||||
@@ -3344,6 +3354,7 @@ class InvoiceAddress(models.Model):
|
||||
self.internal_reference,
|
||||
(_('Beneficiary') + ': ' + self.beneficiary) if self.beneficiary else '',
|
||||
]
|
||||
parts += [f'{k}: {v}' for k, v in self.describe_transmission()]
|
||||
return '\n'.join([str(p).strip() for p in parts if p and str(p).strip()])
|
||||
|
||||
@property
|
||||
@@ -3398,9 +3409,28 @@ class InvoiceAddress(models.Model):
|
||||
'custom_field': self.custom_field,
|
||||
'internal_reference': self.internal_reference,
|
||||
'beneficiary': self.beneficiary,
|
||||
'transmission_type': self.transmission_type,
|
||||
**self.transmission_info,
|
||||
})
|
||||
return d
|
||||
|
||||
def describe_transmission(self):
|
||||
from pretix.base.invoicing.transmission import transmission_types
|
||||
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))
|
||||
return data
|
||||
|
||||
|
||||
def cachedticket_name(instance, filename: str) -> str:
|
||||
secret = get_random_string(length=16, allowed_chars=string.ascii_letters + string.digits)
|
||||
|
||||
Reference in New Issue
Block a user