diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2012-02-10 14:16:58 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2012-02-10 14:16:58 +0100 |
commit | 1aeeaf4eb61bffa368c502f98e7b13c46787068e (patch) | |
tree | 73d9a36e3c01743de2fdb7153dbf7a01ade77631 | |
parent | 473b3cab02927707d11adb6f24e3c2c753ea2036 (diff) |
add an Ust ID Nr. (Umsatzsteur Identifikationnummer, the German VAT number) module
git-svn-id: http://arthurdejong.org/svn/python-stdnum/python-stdnum@104 9dea7c4f-944c-4273-ac1a-574ede026edc
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | stdnum/__init__.py | 1 | ||||
-rw-r--r-- | stdnum/de/__init__.py | 0 | ||||
-rw-r--r-- | stdnum/de/vat.py | 53 | ||||
-rw-r--r-- | tests/test_robustness.doctest | 1 |
5 files changed, 56 insertions, 0 deletions
@@ -25,6 +25,7 @@ Currently this package supports the following formats: * SSN (U.S. Social Security Number) * HETU (Finnish personal identity code) * FPA, ΦΠΑ (Foros Prostithemenis Aksias, the Greek VAT number) + * Ust ID Nr. (Umsatzsteur Identifikationnummer, the German VAT number) * IMEI (International Mobile Equipment Identity) * IMSI (International Mobile Subscriber Identity) * MEID (Mobile Equipment Identifier) diff --git a/stdnum/__init__.py b/stdnum/__init__.py index 25cc715..059314f 100644 --- a/stdnum/__init__.py +++ b/stdnum/__init__.py @@ -39,6 +39,7 @@ Currently this package supports the following formats: * SSN (U.S. Social Security Number) * HETU (Finnish personal identity code) * FPA, ΦΠΑ (Foros Prostithemenis Aksias, the Greek VAT number) + * Ust ID Nr. (Umsatzsteur Identifikationnummer, the German VAT number) * IMEI (International Mobile Equipment Identity) * IMSI (International Mobile Subscriber Identity) * MEID (Mobile Equipment Identifier) diff --git a/stdnum/de/__init__.py b/stdnum/de/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/stdnum/de/__init__.py diff --git a/stdnum/de/vat.py b/stdnum/de/vat.py new file mode 100644 index 0000000..0abc8c5 --- /dev/null +++ b/stdnum/de/vat.py @@ -0,0 +1,53 @@ +# vat.py - functions for handling German VAT numbers +# +# Copyright (C) 2012 Arthur de Jong +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 USA + + +"""Module for handling German VAT (Umsatzsteur Identifikationnummer, Ust +ID Nr.) numbers. + +>>> compact('DE 136,695 976') +'136695976' +>>> is_valid('DE136695976') +True +>>> is_valid('136695978') +False +""" + +from stdnum.iso7064 import mod_11_10 +from stdnum.util import clean + + +def compact(number): + """Convert the number to the minimal representation. This strips the + number of any valid separators and removes surrounding whitespace.""" + number = clean(number, ' -./,').upper().strip() + if number.startswith('DE'): + number = number[2:] + return number + + +def is_valid(number): + """Checks to see if the number provided is a valid VAT number. This checks + the length, formatting and check digit.""" + try: + number = compact(number) + except: + return False + return len(number) == 9 and number.isdigit() and \ + number[0] != '0' and mod_11_10.is_valid(number) diff --git a/tests/test_robustness.doctest b/tests/test_robustness.doctest index 4437ebf..80297cf 100644 --- a/tests/test_robustness.doctest +++ b/tests/test_robustness.doctest @@ -28,6 +28,7 @@ invalid junk. >>> from stdnum import luhn, meid, verhoeff >>> from stdnum.br import cpf >>> from stdnum.cz import rc +>>> from stdnum.de import vat as de_vat >>> from stdnum.fi import hetu >>> from stdnum.fr import siren >>> from stdnum.gr import vat as gr_vat |