From 36efb25b984d34509c4511d0e97c4364ee88099e Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Thu, 4 Feb 2021 17:21:24 +0100 Subject: [PATCH] Invoice address: Always validate that VAT ID is for correct country --- src/pretix/base/forms/questions.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pretix/base/forms/questions.py b/src/pretix/base/forms/questions.py index 4246b9870f..198641b8a3 100644 --- a/src/pretix/base/forms/questions.py +++ b/src/pretix/base/forms/questions.py @@ -848,11 +848,13 @@ class BaseInvoiceAddressForm(forms.ModelForm): ) and len(data.get('name_parts', {})) == 1: # Do not save the country if it is the only field set -- we don't know the user even checked it! self.cleaned_data['country'] = '' + + if data.get('vat_id') and is_eu_country(data.get('country')) and data.get('vat_id')[:2] != cc_to_vat_prefix(str(data.get('country'))): + raise ValidationError(_('Your VAT ID does not match the selected country.')) + if self.validate_vat_id and self.instance.vat_id_validated and 'vat_id' not in self.changed_data: pass elif self.validate_vat_id and data.get('is_business') and is_eu_country(data.get('country')) and data.get('vat_id'): - if data.get('vat_id')[:2] != cc_to_vat_prefix(str(data.get('country'))): - raise ValidationError(_('Your VAT ID does not match the selected country.')) try: result = vat_moss.id.validate(data.get('vat_id')) if result: