lists.arthurdejong.org
RSS feed

python-stdnum commit: r120 - in python-stdnum: . stdnum stdnum/lu tests

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

python-stdnum commit: r120 - in python-stdnum: . stdnum stdnum/lu tests



Author: arthur
Date: Sat Feb 11 21:38:08 2012
New Revision: 120
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=120&view=revision

Log:
add a TVA (Numéro d'identification à la taxe sur la valeur ajoutée, 
Luxembourgian VAT number) module

Added:
   python-stdnum/stdnum/lu/
   python-stdnum/stdnum/lu/__init__.py
   python-stdnum/stdnum/lu/tva.py
Modified:
   python-stdnum/README
   python-stdnum/stdnum/__init__.py
   python-stdnum/tests/test_robustness.doctest

Modified: python-stdnum/README
==============================================================================
--- python-stdnum/README        Sat Feb 11 21:26:46 2012        (r119)
+++ python-stdnum/README        Sat Feb 11 21:38:08 2012        (r120)
@@ -35,6 +35,8 @@
  * BTW, TVA, NWSt (Belgian VAT number)
  * PVN (Pievienotās vērtības nodokļa, Latvian VAT number)
  * CVR (Momsregistreringsnummer, Danish VAT number)
+ * TVA (Numéro d'identification à la taxe sur la valeur ajoutée,
+   Luxembourgian VAT number)
  * IMEI (International Mobile Equipment Identity)
  * IMSI (International Mobile Subscriber Identity)
  * MEID (Mobile Equipment Identifier)

Modified: python-stdnum/stdnum/__init__.py
==============================================================================
--- python-stdnum/stdnum/__init__.py    Sat Feb 11 21:26:46 2012        (r119)
+++ python-stdnum/stdnum/__init__.py    Sat Feb 11 21:38:08 2012        (r120)
@@ -49,6 +49,8 @@
  * BTW, TVA, NWSt (Belgian VAT number)
  * PVN (Pievienotās vērtības nodokļa, Latvian VAT number)
  * CVR (Momsregistreringsnummer, Danish VAT number)
+ * TVA (Numéro d'identification à la taxe sur la valeur ajoutée,
+   Luxembourgian VAT number)
  * IMEI (International Mobile Equipment Identity)
  * IMSI (International Mobile Subscriber Identity)
  * MEID (Mobile Equipment Identifier)

Added: python-stdnum/stdnum/lu/__init__.py
==============================================================================

Added: python-stdnum/stdnum/lu/tva.py
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ python-stdnum/stdnum/lu/tva.py      Sat Feb 11 21:38:08 2012        (r120)
@@ -0,0 +1,59 @@
+# tva.py - functions for handling Luxembourgian VAT numbers
+# coding: utf-8
+#
+# 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 Luxembourgian No. TVA (Numéro d'identification à la
+taxe sur la valeur ajoutée, VAT) numbers.
+
+The number consists of 8 digits of which the last two are check digits.
+
+>>> compact('LU 150 274 42')
+'15027442'
+>>> is_valid('150 274 42')
+True
+>>> is_valid('150 274 43')  # invalid check digits
+False
+"""
+
+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('LU'):
+        number = number[2:]
+    return number
+
+
+def calc_check_digits(number):
+    """Calculate the check digits for the number."""
+    return '%02d' % (int(number) % 89)
+
+
+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 number.isdigit() and len(number) == 8 and \
+           calc_check_digits(number[:6]) == number[-2:]

Modified: python-stdnum/tests/test_robustness.doctest
==============================================================================
--- python-stdnum/tests/test_robustness.doctest Sat Feb 11 21:26:46 2012        
(r119)
+++ python-stdnum/tests/test_robustness.doctest Sat Feb 11 21:38:08 2012        
(r120)
@@ -36,6 +36,7 @@
 >>> from stdnum.fr import siren
 >>> from stdnum.gr import vat as gr_vat
 >>> from stdnum.iso7064 import mod_11_10, mod_11_2, mod_37_2, mod_37_36, 
 >>> mod_97_10
+>>> from stdnum.lu import tva
 >>> from stdnum.lv import pvn
 >>> from stdnum.nl import bsn, onderwijsnummer, btw
 >>> from stdnum.us import ssn
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/