lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 0.8.1-15-ga148835

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 0.8.1-15-ga148835



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".

The branch, master has been updated
       via  a1488350a3085dcc404b9848aa48bf2c875af077 (commit)
      from  4609a22edda673013ff88dd625f4bd48bca35e9b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://arthurdejong.org/git/python-stdnum/commit/?id=a1488350a3085dcc404b9848aa48bf2c875af077

commit a1488350a3085dcc404b9848aa48bf2c875af077
Author: Cédric Krier <ced@b2ck.com>
Date:   Mon Dec 30 21:02:51 2013 +0100

    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: https://github.com/arthurdejong/python-stdnum/pull/4

diff --git a/stdnum/gb/vat.py b/stdnum/gb/vat.py
index f502a5c..1e93cc9 100644
--- a/stdnum/gb/vat.py
+++ b/stdnum/gb/vat.py
@@ -70,13 +70,31 @@ def validate(number):
             pass
         else:
             raise InvalidComponent()
+    elif len(number) == 11 and number[0:6] in ('GD8888', 'HA8888'):
+        if not number[6:].isdigit():
+            raise InvalidFormat()
+        if number.startswith('GD') and int(number[6:9]) < 500:
+            # government department
+            pass
+        elif number.startswith('HA') and int(number[6:9]) >= 500:
+            # health authority
+            pass
+        else:
+            raise InvalidComponent()
+        if int(number[6:9]) % 97 != int(number[9:11]):
+            raise InvalidChecksum()
     elif len(number) in (9, 12):
         if not number.isdigit():
             raise InvalidFormat()
         # standard number: nnn nnnn nn
         # branch trader: nnn nnnn nn nnn (ignore the last thee digits)
-        if checksum(number[:9]) not in (0, 42):
-            raise InvalidChecksum()
+        # restarting: 100 nnnn nn
+        if int(number[:3]) >= 100:
+            if checksum(number[:9]) not in (0, 42, 55):
+                raise InvalidChecksum()
+        else:
+            if checksum(number[:9]) != 0:
+                raise InvalidChecksum()
     else:
         raise InvalidLength()
     return number
diff --git a/tests/test_gb_vat.doctest b/tests/test_gb_vat.doctest
index cdcfe36..151feb4 100644
--- a/tests/test_gb_vat.doctest
+++ b/tests/test_gb_vat.doctest
@@ -29,12 +29,18 @@ Normal values that should just work.
 
 >>> vat.validate('980780684')  # standard number
 '980780684'
+>>> vat.validate('100190874')  # standard number restarting
+'100190874'
 >>> vat.validate('242338087388')  # branch trader
 '242338087388'
 >>> vat.validate('GD100')  # government department
 'GD100'
 >>> vat.validate('HA501')  # health authority
 'HA501'
+>>> vat.validate('GD888810003')  # government department for EU
+'GD888810003'
+>>> vat.validate('HA888856782')  # health authority for EU
+'HA888856782'
 
 
 Invalid long numbers:
@@ -51,6 +57,14 @@ InvalidLength: ...
 Traceback (most recent call last):
     ...
 InvalidFormat: ...
+>>> vat.validate('GD8888567B2')  # invalid digit for EU health authority
+Traceback (most recent call last):
+    ...
+InvalidFormat: ...
+>>> vat.validate('001234567')  # invalid checksum
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
 
 
 Some variations on the short format:
@@ -69,6 +83,22 @@ Traceback (most recent call last):
 InvalidComponent: ...
 
 
+Some variations on the EU format:
+
+>>> vat.validate('GD888860018')  # government department with high number
+Traceback (most recent call last):
+    ...
+InvalidComponent: ...
+>>> vat.validate('HA888820107')  # health authority with low number
+Traceback (most recent call last):
+    ...
+InvalidComponent: ...
+>>> vat.validate('HA888856700') # health authority with invalid checksum
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
+
+
 Formatting tests:
 
 >>> vat.format('980780684')  # standard number

-----------------------------------------------------------------------

Summary of changes:
 stdnum/gb/vat.py          |   22 ++++++++++++++++++++--
 tests/test_gb_vat.doctest |   30 ++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)


hooks/post-receive
-- 
python-stdnum
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/