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:
Raphael Michel
2025-08-19 17:59:45 +02:00
committed by GitHub
parent 37910f6037
commit 05c74b7ad6
65 changed files with 4514 additions and 1825 deletions

View File

@@ -21,38 +21,107 @@
#
import pycountry
from django.http import JsonResponse
from django.shortcuts import get_object_or_404
from django.utils.translation import pgettext
from django_countries.fields import Country
from django_scopes import scope
from pretix.base.addressvalidation import (
COUNTRIES_WITH_STREET_ZIPCODE_AND_CITY_REQUIRED,
)
from pretix.base.invoicing.transmission import get_transmission_types
from pretix.base.models import Organizer
from pretix.base.models.tax import VAT_ID_COUNTRIES
from pretix.base.settings import (
COUNTRIES_WITH_STATE_IN_ADDRESS, COUNTRY_STATE_LABEL,
)
def states(request):
cc = request.GET.get("country", "DE")
def _info(cc):
info = {
'street': {'required': True},
'zipcode': {'required': cc in COUNTRIES_WITH_STREET_ZIPCODE_AND_CITY_REQUIRED},
'city': {'required': cc in COUNTRIES_WITH_STREET_ZIPCODE_AND_CITY_REQUIRED},
'street': {'required': 'if_any'},
'zipcode': {'required': 'if_any' if cc in COUNTRIES_WITH_STREET_ZIPCODE_AND_CITY_REQUIRED else False},
'city': {'required': 'if_any' if cc in COUNTRIES_WITH_STREET_ZIPCODE_AND_CITY_REQUIRED else False},
'state': {
'visible': cc in COUNTRIES_WITH_STATE_IN_ADDRESS,
'required': cc in COUNTRIES_WITH_STATE_IN_ADDRESS,
'required': 'if_any' if cc in COUNTRIES_WITH_STATE_IN_ADDRESS else False,
'label': COUNTRY_STATE_LABEL.get(cc, pgettext('address', 'State')),
},
'vat_id': {'visible': cc in VAT_ID_COUNTRIES, 'required': False},
}
if cc not in COUNTRIES_WITH_STATE_IN_ADDRESS:
return JsonResponse({'data': [], **info, })
return {'data': [], **info}
types, form = COUNTRIES_WITH_STATE_IN_ADDRESS[cc]
statelist = [s for s in pycountry.subdivisions.get(country_code=cc) if s.type in types]
return JsonResponse({
return {
'data': [
{'name': s.name, 'code': s.code[3:]}
for s in sorted(statelist, key=lambda s: s.name)
],
**info,
})
}
def address_form(request):
cc = request.GET.get("country", "DE")
info = _info(cc)
if request.GET.get("invoice") == "true":
# Do not consider live=True, as this does not expose sensitive information and we also want it accessible
# from e.g. the backend when the event is not yet life.
organizer = get_object_or_404(Organizer, slug=request.GET.get("organizer"))
with (scope(organizer=organizer)):
event = get_object_or_404(organizer.events, slug=request.GET.get("event"))
country = Country(cc)
is_business = request.GET.get("is_business") == "business"
selected_transmission_type = request.GET.get("transmission_type")
transmission_type_required = request.GET.get("transmission_type_required") == "true"
info["transmission_types"] = []
for t in get_transmission_types():
if t.is_available(event=event, country=country, is_business=is_business):
result = {"name": str(t.public_name), "code": t.identifier}
if t.exclusive:
info["transmission_types"] = [result]
break
else:
info["transmission_types"].append(result)
info["transmission_type"] = {
# Hide transmission type if email is the only type since that's basically the backwards-compatible
# option
"visible": [t["code"] for t in info["transmission_types"]] != ["email"],
}
if selected_transmission_type not in [t["code"] for t in info["transmission_types"]]:
if transmission_type_required:
# The previously selected transmission type is no longer selectable, e.g. because
# of a country change. To avoid a second roundtrip to this endpoint, let's show
# the fields as if the first remaining option were selected (which is what the client
# side will now do).
selected_transmission_type = info["transmission_types"][0]["code"]
else:
selected_transmission_type = "-"
for transmission_type in get_transmission_types():
required = transmission_type.invoice_address_form_fields_required(
country=country,
is_business=is_business
)
visible = transmission_type.invoice_address_form_fields_visible(
country=country,
is_business=is_business
)
if transmission_type.identifier == selected_transmission_type:
for k, v in info.items():
if k in required:
v["required"] = True
if k in visible:
v["visible"] = True
for k, f in transmission_type.invoice_address_form_fields.items():
info[k] = {
"visible": transmission_type.identifier == selected_transmission_type and k in visible,
"required": transmission_type.identifier == selected_transmission_type and k in required
}
return JsonResponse(info)