python-stdnum commit: r103 - in python-stdnum: . stdnum stdnum/gr tests
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum commit: r103 - in python-stdnum: . stdnum stdnum/gr 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: r103 - in python-stdnum: . stdnum stdnum/gr tests
- Date: Fri, 10 Feb 2012 14:06:31 +0100 (CET)
Author: arthur
Date: Fri Feb 10 14:06:31 2012
New Revision: 103
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=103&view=revision
Log:
add a FPA, ΦΠΑ (Foros Prostithemenis Aksias, the Greek VAT number) module
Added:
python-stdnum/stdnum/gr/
python-stdnum/stdnum/gr/__init__.py
python-stdnum/stdnum/gr/vat.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 5 22:12:18 2012 (r102)
+++ python-stdnum/README Fri Feb 10 14:06:31 2012 (r103)
@@ -24,6 +24,7 @@
company identification number)
* SSN (U.S. Social Security Number)
* HETU (Finnish personal identity code)
+ * FPA, ΦΠΑ (Foros Prostithemenis Aksias, the Greek 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 5 22:12:18 2012 (r102)
+++ python-stdnum/stdnum/__init__.py Fri Feb 10 14:06:31 2012 (r103)
@@ -38,6 +38,7 @@
company identification number)
* SSN (U.S. Social Security Number)
* HETU (Finnish personal identity code)
+ * FPA, ΦΠΑ (Foros Prostithemenis Aksias, the Greek VAT number)
* IMEI (International Mobile Equipment Identity)
* IMSI (International Mobile Subscriber Identity)
* MEID (Mobile Equipment Identifier)
Added: python-stdnum/stdnum/gr/__init__.py
==============================================================================
Added: python-stdnum/stdnum/gr/vat.py
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ python-stdnum/stdnum/gr/vat.py Fri Feb 10 14:06:31 2012 (r103)
@@ -0,0 +1,63 @@
+# vat.py - functions for handling Greek 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 Greek VAT (Foros Prostithemenis Aksias, FPA, ΦΠΑ)
+numbers.
+
+>>> compact('GR 23456783')
+'023456783'
+>>> is_valid('EL 094259216 ')
+True
+>>> is_valid('EL 123456781')
+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('EL') or number.startswith('GR'):
+ number = number[2:]
+ if len(number) == 8:
+ number = '0' + number # old format had 8 digits
+ return number
+
+
+def calc_check_digit(number):
+ """Calculate the check digit. The number passed should not have the
+ check digit included."""
+ checksum = 0
+ for n in number:
+ checksum = checksum * 2 + int(n)
+ return str(checksum * 2 % 11 % 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) == 9 and number.isdigit() and \
+ calc_check_digit(number[:-1]) == number[-1]
Modified: python-stdnum/tests/test_robustness.doctest
==============================================================================
--- python-stdnum/tests/test_robustness.doctest Sun Feb 5 22:12:18 2012
(r102)
+++ python-stdnum/tests/test_robustness.doctest Fri Feb 10 14:06:31 2012
(r103)
@@ -30,6 +30,7 @@
>>> from stdnum.cz import rc
>>> from stdnum.fi import hetu
>>> 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.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/
- python-stdnum commit: r103 - in python-stdnum: . stdnum stdnum/gr tests,
Commits of the python-stdnum project