forked from CGM_Public/pretix_original
Invoice address: Make Peppol required in Belgium if available (Z#23220397) (#5808)
* Invoice address: Make Peppol required in Belgium if available (Z#23220397) * Fix failing test, remove template bit that's now impossible
This commit is contained in:
@@ -191,7 +191,7 @@ class InvoiceAddressSerializer(I18nAwareModelSerializer):
|
|||||||
{"transmission_info": {r: "This field is required for the selected type of invoice transmission."}}
|
{"transmission_info": {r: "This field is required for the selected type of invoice transmission."}}
|
||||||
)
|
)
|
||||||
break # do not call else branch of for loop
|
break # do not call else branch of for loop
|
||||||
elif t.exclusive:
|
elif t.is_exclusive(self.context["request"].event, data.get("country"), data.get("is_business")):
|
||||||
if t.is_available(self.context["request"].event, data.get("country"), data.get("is_business")):
|
if t.is_available(self.context["request"].event, data.get("country"), data.get("is_business")):
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
"transmission_type": "The transmission type '%s' must be used for this country or address type." % (
|
"transmission_type": "The transmission type '%s' must be used for this country or address type." % (
|
||||||
|
|||||||
@@ -1417,7 +1417,7 @@ class BaseInvoiceAddressForm(forms.ModelForm):
|
|||||||
|
|
||||||
self.instance.transmission_type = transmission_type.identifier
|
self.instance.transmission_type = transmission_type.identifier
|
||||||
self.instance.transmission_info = transmission_type.form_data_to_transmission_info(data)
|
self.instance.transmission_info = transmission_type.form_data_to_transmission_info(data)
|
||||||
elif transmission_type.exclusive:
|
elif transmission_type.is_exclusive(self.event, data.get("country"), data.get("is_business")):
|
||||||
if transmission_type.is_available(self.event, data.get("country"), data.get("is_business")):
|
if transmission_type.is_available(self.event, data.get("country"), data.get("is_business")):
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
"transmission_type": "The transmission type '%s' must be used for this country or address type." % (
|
"transmission_type": "The transmission type '%s' must be used for this country or address type." % (
|
||||||
|
|||||||
@@ -36,9 +36,11 @@ class ItalianSdITransmissionType(TransmissionType):
|
|||||||
identifier = "it_sdi"
|
identifier = "it_sdi"
|
||||||
verbose_name = pgettext_lazy("italian_invoice", "Italian Exchange System (SdI)")
|
verbose_name = pgettext_lazy("italian_invoice", "Italian Exchange System (SdI)")
|
||||||
public_name = pgettext_lazy("italian_invoice", "Exchange System (SdI)")
|
public_name = pgettext_lazy("italian_invoice", "Exchange System (SdI)")
|
||||||
exclusive = True
|
|
||||||
enforce_transmission = True
|
enforce_transmission = True
|
||||||
|
|
||||||
|
def is_exclusive(self, event, country: Country, is_business: bool) -> bool:
|
||||||
|
return str(country) == "IT"
|
||||||
|
|
||||||
def is_available(self, event, country: Country, is_business: bool):
|
def is_available(self, event, country: Country, is_business: bool):
|
||||||
return str(country) == "IT" and super().is_available(event, country, is_business)
|
return str(country) == "IT" and super().is_available(event, country, is_business)
|
||||||
|
|
||||||
|
|||||||
@@ -179,6 +179,12 @@ class PeppolTransmissionType(TransmissionType):
|
|||||||
def is_available(self, event, country: Country, is_business: bool):
|
def is_available(self, event, country: Country, is_business: bool):
|
||||||
return is_business and super().is_available(event, country, is_business)
|
return is_business and super().is_available(event, country, is_business)
|
||||||
|
|
||||||
|
def is_exclusive(self, event, country: Country, is_business: bool) -> bool:
|
||||||
|
if is_business and str(country) == "BE" and event and event.settings.invoice_address_from_country == "BE":
|
||||||
|
# Peppol is required to be used for intra-Belgian B2B invoices
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def invoice_address_form_fields(self) -> dict:
|
def invoice_address_form_fields(self) -> dict:
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -58,15 +58,6 @@ class TransmissionType:
|
|||||||
"""
|
"""
|
||||||
return 100
|
return 100
|
||||||
|
|
||||||
@property
|
|
||||||
def exclusive(self) -> bool:
|
|
||||||
"""
|
|
||||||
If a transmission type is exclusive, no other type can be chosen if this type is
|
|
||||||
available. Use e.g. if a certain transmission type is legally required in a certain
|
|
||||||
jurisdiction.
|
|
||||||
"""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def enforce_transmission(self) -> bool:
|
def enforce_transmission(self) -> bool:
|
||||||
"""
|
"""
|
||||||
@@ -82,6 +73,15 @@ class TransmissionType:
|
|||||||
for provider, _ in providers
|
for provider, _ in providers
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def is_exclusive(self, event, country: Country, is_business: bool) -> bool:
|
||||||
|
"""
|
||||||
|
If a transmission type is exclusive, no other type can be chosen if this type is
|
||||||
|
available. Use e.g. if a certain transmission type is legally required in a certain
|
||||||
|
jurisdiction. Event can be None in organizer-level contexts. Exclusiveness has no effect if
|
||||||
|
the type is not available.
|
||||||
|
"""
|
||||||
|
return False
|
||||||
|
|
||||||
def invoice_address_form_fields_required(self, country: Country, is_business: bool):
|
def invoice_address_form_fields_required(self, country: Country, is_business: bool):
|
||||||
return set()
|
return set()
|
||||||
|
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ def address_form(request):
|
|||||||
for t in get_transmission_types():
|
for t in get_transmission_types():
|
||||||
if t.is_available(event=event, country=country, is_business=is_business):
|
if t.is_available(event=event, country=country, is_business=is_business):
|
||||||
result = {"name": str(t.public_name), "code": t.identifier}
|
result = {"name": str(t.public_name), "code": t.identifier}
|
||||||
if t.exclusive:
|
if t.is_exclusive(event=event, country=country, is_business=is_business):
|
||||||
info["transmission_types"] = [result]
|
info["transmission_types"] = [result]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -111,11 +111,6 @@
|
|||||||
<span class="text-success">
|
<span class="text-success">
|
||||||
<span class="fa fa-check fa-fw"></span>
|
<span class="fa fa-check fa-fw"></span>
|
||||||
{% trans "Available" %}
|
{% trans "Available" %}
|
||||||
{% if t.exclusive %}
|
|
||||||
<span data-toggle="tooltip" title="{% trans "When this type is available for an invoice address, no other type can be selected." %}">
|
|
||||||
{% trans "(exclusive)" %}
|
|
||||||
</span>
|
|
||||||
{% endif %}
|
|
||||||
</span>
|
</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="text-muted">
|
<span class="text-muted">
|
||||||
|
|||||||
Reference in New Issue
Block a user