python-stdnum commit: r142 - in python-stdnum: . stdnum stdnum/se tests
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum commit: r142 - in python-stdnum: . stdnum stdnum/se 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: r142 - in python-stdnum: . stdnum stdnum/se tests
- Date: Sat, 18 Feb 2012 16:38:51 +0100 (CET)
Author: arthur
Date: Sat Feb 18 16:38:51 2012
New Revision: 142
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=142&view=revision
Log:
add a VAT (Moms, Mervärdesskatt, Swedish VAT number) module
Added:
python-stdnum/stdnum/se/
python-stdnum/stdnum/se/__init__.py
python-stdnum/stdnum/se/vat.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 18 16:05:46 2012 (r141)
+++ python-stdnum/README Sat Feb 18 16:38:51 2012 (r142)
@@ -55,6 +55,7 @@
* VAT (Maltese VAT number)
* NIP (Numer Identyfikacji Podatkowej, Polish VAT number)
* ID za DDV (Davčna številka, Slovenian VAT number)
+ * VAT (Moms, Mervärdesskatt, Swedish 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 18 16:05:46 2012 (r141)
+++ python-stdnum/stdnum/__init__.py Sat Feb 18 16:38:51 2012 (r142)
@@ -69,6 +69,7 @@
* VAT (Maltese VAT number)
* NIP (Numer Identyfikacji Podatkowej, Polish VAT number)
* ID za DDV (Davčna številka, Slovenian VAT number)
+ * VAT (Moms, Mervärdesskatt, Swedish VAT number)
* IMEI (International Mobile Equipment Identity)
* IMSI (International Mobile Subscriber Identity)
* MEID (Mobile Equipment Identifier)
Added: python-stdnum/stdnum/se/__init__.py
==============================================================================
Added: python-stdnum/stdnum/se/vat.py
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ python-stdnum/stdnum/se/vat.py Sat Feb 18 16:38:51 2012 (r142)
@@ -0,0 +1,55 @@
+# vat.py - functions for handling Swedish 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 Swedish VAT (Moms, Mervärdesskatt) numbers.
+
+The Momsregistreringsnummer consists of 12 digits of which the last two
+should be 01. The first 10 digits should have a valid Luhn checksum.
+
+>>> compact('SE 123456789701')
+'123456789701'
+>>> is_valid('123456789701')
+True
+>>> is_valid('123456789101') # invalid check digits
+False
+"""
+
+from stdnum import luhn
+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('SE'):
+ number = number[2:]
+ return number
+
+
+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) == 12 and \
+ luhn.is_valid(number[:-2]) and 0 < int(number[-2:]) < 95
Modified: python-stdnum/tests/test_robustness.doctest
==============================================================================
--- python-stdnum/tests/test_robustness.doctest Sat Feb 18 16:05:46 2012
(r141)
+++ python-stdnum/tests/test_robustness.doctest Sat Feb 18 16:38:51 2012
(r142)
@@ -50,6 +50,7 @@
>>> from stdnum.pl import nip
>>> from stdnum.pt import nif as pt_nif
>>> from stdnum.ro import cf, cnp
+>>> from stdnum.se import vat as se_vat
>>> from stdnum.si import ddv
>>> from stdnum.sk import dph
>>> 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: r142 - in python-stdnum: . stdnum stdnum/se tests,
Commits of the python-stdnum project