python-stdnum commit: r133 - in python-stdnum: . stdnum stdnum/hu tests
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum commit: r133 - in python-stdnum: . stdnum stdnum/hu 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: r133 - in python-stdnum: . stdnum stdnum/hu tests
- Date: Fri, 17 Feb 2012 17:01:59 +0100 (CET)
Author: arthur
Date: Fri Feb 17 17:01:58 2012
New Revision: 133
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=133&view=revision
Log:
add an ANUM (Közösségi adószám, Hungarian VAT number) module
Added:
python-stdnum/stdnum/hu/
python-stdnum/stdnum/hu/__init__.py
python-stdnum/stdnum/hu/anum.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:36:45 2012 (r132)
+++ python-stdnum/README Fri Feb 17 17:01:58 2012 (r133)
@@ -46,6 +46,7 @@
* IČ DPH (Identifikačné číslo pre daň z pridanej hodnoty, Slovak VAT number)
* ALV nro (Arvonlisäveronumero, Finnish VAT number)
* DIČ (Daňové identifikační číslo, Czech VAT number)
+ * ANUM (Közösségi adószám, Hungarian 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:36:45 2012 (r132)
+++ python-stdnum/stdnum/__init__.py Fri Feb 17 17:01:58 2012 (r133)
@@ -60,6 +60,7 @@
* IČ DPH (Identifikačné číslo pre daň z pridanej hodnoty, Slovak VAT number)
* ALV nro (Arvonlisäveronumero, Finnish VAT number)
* DIČ (Daňové identifikační číslo, Czech VAT number)
+ * ANUM (Közösségi adószám, Hungarian VAT number)
* IMEI (International Mobile Equipment Identity)
* IMSI (International Mobile Subscriber Identity)
* MEID (Mobile Equipment Identifier)
Added: python-stdnum/stdnum/hu/__init__.py
==============================================================================
Added: python-stdnum/stdnum/hu/anum.py
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ python-stdnum/stdnum/hu/anum.py Fri Feb 17 17:01:58 2012 (r133)
@@ -0,0 +1,59 @@
+# anum.py - functions for handling Hungarian 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 Hungarian ANUM (Közösségi adószám, VAT) numbers.
+
+It is an 8-digit taxpayer registration number that includes a weighted
+checksum.
+
+>>> compact('HU-12892312')
+'12892312'
+>>> is_valid('HU-12892312')
+True
+>>> is_valid('HU-12892313') # 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('HU'):
+ number = number[2:]
+ return number
+
+
+def checksum(number):
+ """Calculate the checksum."""
+ weights = (9, 7, 3, 1, 9, 7, 3, 1)
+ return sum(weights[i] * 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 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:36:45 2012
(r132)
+++ python-stdnum/tests/test_robustness.doctest Fri Feb 17 17:01:58 2012
(r133)
@@ -37,6 +37,7 @@
>>> from stdnum.fi import hetu, alv
>>> from stdnum.fr import siren
>>> from stdnum.gr import vat as gr_vat
+>>> from stdnum.hu import anum
>>> 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
--
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: r133 - in python-stdnum: . stdnum stdnum/hu tests,
Commits of the python-stdnum project