From 2619a658c96d8890413dfedaf5def9af8db46b15 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Thu, 23 May 2024 11:19:59 +0200 Subject: [PATCH] Widget: Allow passing more invoice data fields (#4162) --- doc/user/events/widget.rst | 6 +++--- src/pretix/base/forms/questions.py | 2 +- src/pretix/presale/checkoutflow.py | 12 ++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/doc/user/events/widget.rst b/doc/user/events/widget.rst index 76e6d58757..3267c4a000 100644 --- a/doc/user/events/widget.rst +++ b/doc/user/events/widget.rst @@ -339,9 +339,9 @@ Currently, the following attributes are understood by pretix itself: ``data-attendee-name``, which will pre-fill the last part of the name, whatever that is. * ``data-invoice-address-FIELD`` will pre-fill the corresponding field of the invoice address. Possible values for - ``FIELD`` are ``company``, ``street``, ``zipcode``, ``city`` and ``country``, as well as fields specified by the - naming scheme such as ``name-title`` or ``name-given-name`` (see above). ``country`` expects a two-character - country code. + ``FIELD`` are ``company``, ``street``, ``zipcode``, ``city``, ``country``, ``internal-reference``, ``vat-id``, and + ``custom-field``, as well as fields specified by the naming scheme such as ``name-title`` or ``name-given-name`` + (see above). ``country`` expects a two-character country code. * If ``data-fix="true"`` is given, the user will not be able to change the other given values later. This currently only works for the order email address as well as the invoice address. Attendee-level fields and questions can diff --git a/src/pretix/base/forms/questions.py b/src/pretix/base/forms/questions.py index f8e8436d96..a2acc2f487 100644 --- a/src/pretix/base/forms/questions.py +++ b/src/pretix/base/forms/questions.py @@ -1171,7 +1171,7 @@ class BaseInvoiceAddressForm(forms.ModelForm): self.instance.vat_id_validated = False messages.warning(self.request, e.message) else: - raise ValidationError(e.message) + raise ValidationError({"vat_id": e.message}) except VATIDTemporaryError as e: self.instance.vat_id_validated = False if self.request and self.vat_warning: diff --git a/src/pretix/presale/checkoutflow.py b/src/pretix/presale/checkoutflow.py index 4e85143349..49298d2ce4 100644 --- a/src/pretix/presale/checkoutflow.py +++ b/src/pretix/presale/checkoutflow.py @@ -827,6 +827,9 @@ class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep): 'zipcode': wd.get('invoice-address-zipcode', ''), 'city': wd.get('invoice-address-city', ''), 'country': wd.get('invoice-address-country', ''), + 'internal_reference': wd.get('invoice-address-internal-reference', ''), + 'custom_field': wd.get('invoice-address-custom-field', ''), + 'vat_id': wd.get('invoice-address-vat-id', ''), } else: wd_initial = { @@ -893,6 +896,15 @@ class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep): if failed: messages.error(request, _("We had difficulties processing your input. Please review the errors below.")) + if "vat_id" in self.invoice_form.errors: + # If an invalid VAT ID was given through the widget together with data-fix="true", let's un-block + # the field to prevent a deadlock. + widget_data = self.cart_session.get('widget_data', {}) + if "invoice-address-vat-id" in widget_data: + vat_id = widget_data.pop("invoice-address-vat-id", None) + self.invoice_form.data["vat_id"] = vat_id + self.invoice_form.fields["vat_id"].disabled = False + self.cart_session['widget_data'] = widget_data return self.render() self.cart_session['email'] = self.contact_form.cleaned_data['email'] d = dict(self.contact_form.cleaned_data)