8000 Add some new VAT numbers for GB · sharoonthomas/python-stdnum@a148835 · GitHub
[go: up one dir, main page]

Skip to content

Commit a148835

Browse files
cedkarthurdejong
authored andcommitted
Add some new VAT numbers for GB
Add support for restarting from November 2009 using 9755. Add support for EU format of health authorities See: arthurdejong#4
1 parent 4609a22 commit a148835

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

stdnum/gb/vat.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,31 @@ def validate(number):
7070
pass
7171
else:
7272
raise InvalidComponent()
73+
elif len(number) == 11 and number[0:6] in ('GD8888', 'HA8888'):
74+
if not number[6:].isdigit():
75+
raise InvalidFormat()
76+
if number.startswith('GD') and int(number[6:9]) < 500:
77+
# government department
78+
pass
79+
elif number.startswith('HA') and int(number[6:9]) >= 500:
80+
# health authority
81+
pass
82+
else:
83+
raise InvalidComponent()
84+
if int(number[6:9]) % 97 != int(number[9:11]):
85+
raise InvalidChecksum()
7386
elif len(number) in (9, 12):
7487
if not number.isdigit():
7588
raise InvalidFormat()
7689
# standard number: nnn nnnn nn
7790
# branch trader: nnn nnnn nn nnn (ignore the last thee digits)
78-
if checksum(number[:9]) not in (0, 42):
79-
raise InvalidChecksum()
91+
# restarting: 100 nnnn nn
92+
if int(number[:3]) >= 100:
93+
if checksum(number[:9]) not in (0, 42, 55):
94+
raise InvalidChecksum()
95+
else:
96+
if checksum(number[:9]) != 0:
97+
raise InvalidChecksum()
8098
else:
8199
raise InvalidLength< 10000 /span>()
82100
return number

tests/test_gb_vat.doctest

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ Normal values that should just work.
2929

3030
>>> vat.validate('980780684') # standard number
3131
'980780684'
32+
>>> vat.validate('100190874') # standard number restarting
33+
'100190874'
3234
>>> vat.validate('242338087388') # branch trader
3335
'242338087388'
3436
>>> vat.validate('GD100') # government department
3537
'GD100'
3638
>>> vat.validate('HA501') # health authority
3739
'HA501'
40+
>>> vat.validate('GD888810003') # government department for EU
41+
'GD888810003'
42+
>>> vat.validate('HA888856782') # health authority for EU
43+
'HA888856782'
3844

3945

4046
Invalid long numbers:
@@ -51,6 +57,14 @@ InvalidLength: ...
5157
Traceback (most recent call last):
5258
...
5359
InvalidFormat: ...
60+
>>> vat.validate('GD8888567B2') # invalid digit for EU health authority
61+
Traceback (most recent call last):
62+
...
63+
InvalidFormat: ...
64+
>>> vat.validate('001234567') # invalid checksum
65+
Traceback (most recent call last):
66+
...
67+
InvalidChecksum: ...
5468

5569

5670
Some variations on the short format:
@@ -69,6 +83,22 @@ Traceback (most recent call last):
6983
InvalidComponent: ...
7084

7185

86+
Some variations on the EU format:
87+
88+
>>> vat.validate('GD888860018') # government department with high number
89+
Traceback (most recent call last):
90+
...
91+
InvalidComponent: ...
92+
>>> vat.validate('HA888820107') # health authority with low number
93+
Traceback (most recent call last):
94+
...
95+
InvalidComponent: ...
96+
>>> vat.validate('HA888856700') # health authority with invalid checksum
97+
Traceback (most recent call last):
98+
...
99+
InvalidChecksum: ...
100+
101+
72102
Formatting tests:
73103

74104
>>> vat.format('980780684') # standard number

0 commit comments

Comments
 (0)
0