python-stdnum commit: r124 - in python-stdnum: . stdnum stdnum/it tests
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum commit: r124 - in python-stdnum: . stdnum stdnum/it tests
- From: Commits of the python-stdnum project <python-stdnum-commits [at] lists.arthurdejong.org>
- To: python-stdnum-commits [at] lists.arthurdejong.org
- Reply-to: python-stdnum-users [at] lists.arthurdejong.org
- Subject: python-stdnum commit: r124 - in python-stdnum: . stdnum stdnum/it tests
- Date: Sun, 12 Feb 2012 16:29:45 +0100 (CET)
Author: arthur
Date: Sun Feb 12 16:29:44 2012
New Revision: 124
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=124&view=revision
Log:
add a Partita IVA (Italian VAT number) module
Added:
python-stdnum/stdnum/it/
python-stdnum/stdnum/it/__init__.py
python-stdnum/stdnum/it/iva.py
Modified:
python-stdnum/README
python-stdnum/stdnum/__init__.py
python-stdnum/tests/test_robustness.doctest
Modified: python-stdnum/README
==============================================================================
--- python-stdnum/README Sun Feb 12 15:26:44 2012 (r123)
+++ python-stdnum/README Sun Feb 12 16:29:44 2012 (r124)
@@ -39,6 +39,7 @@
* TVA (Numéro d'identification à la taxe sur la valeur ajoutée,
Luxembourgian VAT number)
* CF (Cod de înregistrare în scopuri de TVA, Romanian VAT number)
+ * Partita IVA (Italian 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 Sun Feb 12 15:26:44 2012 (r123)
+++ python-stdnum/stdnum/__init__.py Sun Feb 12 16:29:44 2012 (r124)
@@ -53,6 +53,7 @@
* TVA (Numéro d'identification à la taxe sur la valeur ajoutée,
Luxembourgian VAT number)
* CF (Cod de înregistrare în scopuri de TVA, Romanian VAT number)
+ * Partita IVA (Italian VAT number)
* IMEI (International Mobile Equipment Identity)
* IMSI (International Mobile Subscriber Identity)
* MEID (Mobile Equipment Identifier)
Added: python-stdnum/stdnum/it/__init__.py
==============================================================================
Added: python-stdnum/stdnum/it/iva.py
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ python-stdnum/stdnum/it/iva.py Sun Feb 12 16:29:44 2012 (r124)
@@ -0,0 +1,68 @@
+# vat.py - functions for handling Italian 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 Italian IVA (Partita IVA (Imposta sul valore
+aggiunto), VAT) numbers.
+
+The number consists of 11 digits. The first 7 digits are a company
+identifier, tge next 3 refer to the province of residence and the last is
+a check digit.
+
+Note that the fiscal code for individuals is not accepted as valid code
+for intracommunity VAT related operations so it is ignored here.
+
+>>> compact('IT 00743110157')
+'00743110157'
+>>> is_valid('00743110157')
+True
+>>> is_valid('00743110158') # invalid check digit
+False
+"""
+
+from stdnum.util import clean, digitsum
+
+
+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('IT'):
+ number = number[2:]
+ return number
+
+
+def checksum(number):
+ """Calculate the checksum."""
+ return digitsum(
+ (1 + (i % 2)) * int(n)
+ for i, n in enumerate(number)) % 10
+
+
+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) == 11 and number.isdigit() and \
+ int(number[0:7]) > 0 and (
+ '001' <= number[7:10] <= '100' or
+ number[7:10] in ('120', '121', '888', '999')
+ ) and checksum(number) == 0
Modified: python-stdnum/tests/test_robustness.doctest
==============================================================================
--- python-stdnum/tests/test_robustness.doctest Sun Feb 12 15:26:44 2012
(r123)
+++ python-stdnum/tests/test_robustness.doctest Sun Feb 12 16:29:44 2012
(r124)
@@ -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.it import iva
>>> from stdnum.lu import tva
>>> from stdnum.lv import pvn
>>> from stdnum.nl import bsn, onderwijsnummer, btw
--
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/
- python-stdnum commit: r124 - in python-stdnum: . stdnum stdnum/it tests,
Commits of the python-stdnum project