forked from CGM_Public/pretix_original
Fix crash on VAT IDs with missing country prefix
This commit is contained in:
@@ -94,6 +94,10 @@ def _validate_vat_id_NO(vat_id, country_code):
|
|||||||
def _validate_vat_id_EU(vat_id, country_code):
|
def _validate_vat_id_EU(vat_id, country_code):
|
||||||
# Inspired by vat_moss library
|
# Inspired by vat_moss library
|
||||||
vat_id = vat_moss.id.normalize(vat_id)
|
vat_id = vat_moss.id.normalize(vat_id)
|
||||||
|
|
||||||
|
if not vat_id or len(vat_id) < 3:
|
||||||
|
raise VATIDFinalError(error_messages['invalid'])
|
||||||
|
|
||||||
number = vat_id[2:]
|
number = vat_id[2:]
|
||||||
|
|
||||||
if vat_id[:2] != cc_to_vat_prefix(country_code):
|
if vat_id[:2] != cc_to_vat_prefix(country_code):
|
||||||
|
|||||||
@@ -16,6 +16,12 @@ def test_eu_invalid_format():
|
|||||||
validate_vat_id('AT12345', 'AT')
|
validate_vat_id('AT12345', 'AT')
|
||||||
|
|
||||||
|
|
||||||
|
@responses.activate
|
||||||
|
def test_eu_no_prefix():
|
||||||
|
with pytest.raises(VATIDFinalError):
|
||||||
|
validate_vat_id('12345', 'AT')
|
||||||
|
|
||||||
|
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_eu_country_mismatch():
|
def test_eu_country_mismatch():
|
||||||
with pytest.raises(VATIDFinalError):
|
with pytest.raises(VATIDFinalError):
|
||||||
|
|||||||
Reference in New Issue
Block a user