8000 Fix vatin number compacting for "EU" VAT numbers · arthurdejong/python-stdnum@1e412ee · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e412ee

Browse files
committed
Fix vatin number compacting for "EU" VAT numbers
Thanks Davide Walder for finding this. Closes #427
1 parent 2535bbf commit 1e412ee

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

stdnum/vatin.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# vatin.py - function to validate any given VATIN.
22
#
33
# Copyright (C) 2020 Leandro Regueiro
4-
# Copyright (C) 2021 Arthur de Jong
4+
# Copyright (C) 2021-2024 Arthur de Jong
55
#
66
# This library is free software; you can redistribute it and/or
77
# modify it under the terms of the GNU Lesser General Public
@@ -74,7 +74,10 @@ def compact(number):
7474
"""Convert the number to the minimal representation."""
7575
number = clean(number).strip()
7676
module = _get_cc_module(number[:2])
77-
return number[:2] + module.compact(number[2:])
77+
try:
78+
return number[:2].upper() + module.compact(number[2:])
79+
except ValidationError:
80+
return module.compact(number)
7881

7982

8083
def validate(number):

tests/test_vatin.doctest

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
test_vatin.doctest - more detailed doctests for stdnum.vatin module
22

33
Copyright (C) 2020 Leandro Regueiro
4-
Copyright (C) 2021 Arthur de Jong
4+
Copyright (C) 2021-2024 Arthur de Jong
55

66
This library is free software; you can redistribute it and/or
77
modify it under the terms of the GNU Lesser General Public
@@ -96,3 +96,11 @@ False
9696
False
9797
>>> vatin.is_valid('US')
9898
False
99+
100+
101+
Check for VAT numbers that cannot be compacted without EU prefix:
102+
103+
>>> vatin.is_valid('EU191849184')
104+
True
105+
>>> vatin.compact('EU191849184')
106+
'EU191849184'

0 commit comments

Comments
 (0)
0