python-stdnum commit: r131 - in python-stdnum: . stdnum stdnum/fi tests
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum commit: r131 - in python-stdnum: . stdnum stdnum/fi 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: r131 - in python-stdnum: . stdnum stdnum/fi tests
- Date: Fri, 17 Feb 2012 16:15:18 +0100 (CET)
Author: arthur
Date: Fri Feb 17 16:15:17 2012
New Revision: 131
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=131&view=revision
Log:
add an ALV nro (Arvonlisäveronumero, Finnish VAT number) module
Added:
python-stdnum/stdnum/fi/alv.py
Modified:
python-stdnum/README
python-stdnum/stdnum/__init__.py
python-stdnum/tests/test_robustness.doctest
Modified: python-stdnum/README
==============================================================================
--- python-stdnum/README Fri Feb 17 16:02:05 2012 (r130)
+++ python-stdnum/README Fri Feb 17 16:15:17 2012 (r131)
@@ -44,6 +44,7 @@
* UID (Umsatzsteuer-Identifikationsnummer, Austrian VAT number)
* NIF (Número de identificação fiscal, Portuguese VAT number)
* IČ DPH (Identifikačné číslo pre daň z pridanej hodnoty, Slovak VAT number)
+ * ALV nro (Arvonlisäveronumero, Finnish 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 Fri Feb 17 16:02:05 2012 (r130)
+++ python-stdnum/stdnum/__init__.py Fri Feb 17 16:15:17 2012 (r131)
@@ -58,6 +58,7 @@
* UID (Umsatzsteuer-Identifikationsnummer, Austrian VAT number)
* NIF (Número de identificação fiscal, Portuguese VAT number)
* IČ DPH (Identifikačné číslo pre daň z pridanej hodnoty, Slovak VAT number)
+ * ALV nro (Arvonlisäveronumero, Finnish VAT number)
* IMEI (International Mobile Equipment Identity)
* IMSI (International Mobile Subscriber Identity)
* MEID (Mobile Equipment Identifier)
Added: python-stdnum/stdnum/fi/alv.py
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ python-stdnum/stdnum/fi/alv.py Fri Feb 17 16:15:17 2012 (r131)
@@ -0,0 +1,58 @@
+# vat.py - functions for handling Finnish 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 Finnish ALV nro (Arvonlisäveronumero, VAT) numbers.
+
+The number is an 8-digit code with a weighted checksum.
+
+>>> compact('FI- 2077474-0')
+'20774740'
+>>> is_valid('FI 20774740')
+True
+>>> is_valid('FI 20774741') # invalid check digit
+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('FI'):
+ number = number[2:]
+ return number
+
+
+def checksum(number):
+ """Calculate the checksum."""
+ weights = (7, 9, 10, 5, 8, 4, 2, 1)
+ return sum(weights[i] * int(n) for i, n in enumerate(number)) % 11
+
+
+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 checksum(number) == 0
Modified: python-stdnum/tests/test_robustness.doctest
==============================================================================
--- python-stdnum/tests/test_robustness.doctest Fri Feb 17 16:02:05 2012
(r130)
+++ python-stdnum/tests/test_robustness.doctest Fri Feb 17 16:15:17 2012
(r131)
@@ -34,7 +34,7 @@
>>> from stdnum.de import vat as de_vat
>>> from stdnum.dk import cvr
>>> from stdnum.es import cif, dni, nie, nif as es_nif
->>> from stdnum.fi import hetu
+>>> from stdnum.fi import hetu, alv
>>> 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
--
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: r131 - in python-stdnum: . stdnum stdnum/fi tests,
Commits of the python-stdnum project