python-stdnum branch master updated. 1.0-7-g699b340
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.0-7-g699b340
- 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 branch master updated. 1.0-7-g699b340
- Date: Fri, 17 Apr 2015 22:40:48 +0200 (CEST)
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".
The branch, master has been updated
via 699b3406ff070f89b6b5cc37a949c84495c04b0f (commit)
from 75bcef02660da492bcbaa1bad4a15a55f64a6df9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://arthurdejong.org/git/python-stdnum/commit/?id=699b3406ff070f89b6b5cc37a949c84495c04b0f
commit 699b3406ff070f89b6b5cc37a949c84495c04b0f
Author: Tuomas Toivonen <toivotuo@kasvua.org>
Date: Sat Apr 11 21:52:12 2015 +0200
Add support for Norwegian organisation and VAT numbers
This commit also includes changes from Tomas Thor Jonsson
<benregn@gmail.com>.
diff --git a/stdnum/no/__init__.py b/stdnum/no/__init__.py
new file mode 100644
index 0000000..c92ea78
--- /dev/null
+++ b/stdnum/no/__init__.py
@@ -0,0 +1,24 @@
+# __init__.py - collection of Norwegian numbers
+# coding: utf-8
+#
+# Copyright (C) 2015 Tuomas Toivonen
+#
+# 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
+
+"""Collection of Norwegian numbers."""
+
+# provide vat as an alias
+from stdnum.no import mva as vat
diff --git a/stdnum/no/mva.py b/stdnum/no/mva.py
new file mode 100644
index 0000000..f3be4e7
--- /dev/null
+++ b/stdnum/no/mva.py
@@ -0,0 +1,73 @@
+# mva.py - functions for handling Norwegian VAT numbers
+# coding: utf-8
+#
+# Copyright (C) 2015 Tuomas Toivonen
+# Copyright (C) 2015 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
+
+"""MVA (Merverdiavgift, Norwegian VAT number).
+
+The VAT number is the standard Norwegian organisation number
+(Organisasjonsnummer) with 'MVA' as suffix.
+
+>>> validate('NO 995 525 828 MVA')
+'995525828MVA'
+>>> validate('NO 995 525 829 MVA')
+Traceback (most recent call last):
+ ...
+InvalidChecksum: ...
+>>> format('995525828MVA')
+'NO 995 525 828 MVA'
+"""
+
+from stdnum.exceptions import *
+from stdnum.no import orgnr
+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('NO'):
+ number = number[2:]
+ return number
+
+
+def validate(number):
+ """Checks to see if the number provided is a valid MVA number. This
+ checks the length, formatting and check digit."""
+ number = compact(number)
+ if not number.endswith('MVA'):
+ raise InvalidFormat()
+ orgnr.validate(number[:-3])
+ return number
+
+
+def is_valid(number):
+ """Checks to see if the number provided is a valid MVA number. This
+ checks the length, formatting and check digit."""
+ try:
+ return bool(validate(number))
+ except ValidationError:
+ return False
+
+
+def format(number):
+ """Reformat the passed number to the standard format."""
+ number = compact(number)
+ return 'NO ' + orgnr.format(number[:9]) + ' ' + number[9:]
diff --git a/stdnum/no/orgnr.py b/stdnum/no/orgnr.py
new file mode 100644
index 0000000..6448186
--- /dev/null
+++ b/stdnum/no/orgnr.py
@@ -0,0 +1,79 @@
+# orgnr.py - functions for handling Norwegian organisation numbers
+# coding: utf-8
+#
+# Copyright (C) 2014 Tomas Thor Jonsson
+# Copyright (C) 2015 Tuomas Toivonen
+# Copyright (C) 2015 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
+
+"""Orgnr (Organisasjonsnummer, Norwegian organisation number).
+
+The Organisasjonsnummer is a 9-digit number with a straightforward check
+mechanism.
+
+>>> validate('988 077 917')
+'988077917'
+>>> validate('988 077 918')
+Traceback (most recent call last):
+ ...
+InvalidChecksum: ...
+>>> format('988077917')
+'988 077 917'
+"""
+
+from stdnum.exceptions import *
+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."""
+ return clean(number, ' ').strip()
+
+
+def checksum(number):
+ """Calculate the checksum."""
+ weights = (3, 2, 7, 6, 5, 4, 3, 2, 1)
+ return sum(weights[i] * int(n) for i, n in enumerate(number)) % 11
+
+
+def validate(number):
+ """Checks to see if the number provided is a valid organisation number.
+ This checks the length, formatting and check digit."""
+ number = compact(number)
+ if not number.isdigit():
+ raise InvalidFormat()
+ if len(number) != 9:
+ raise InvalidLength()
+ if checksum(number) != 0:
+ raise InvalidChecksum()
+ return number
+
+
+def is_valid(number):
+ """Checks to see if the number provided is a valid organisation number.
+ This checks the length, formatting and check digit."""
+ try:
+ return bool(validate(number))
+ except ValidationError:
+ return False
+
+
+def format(number):
+ """Reformat the passed number to the standard format."""
+ number = compact(number)
+ return number[:3] + ' ' + number[3:6] + ' ' + number[6:]
-----------------------------------------------------------------------
Summary of changes:
stdnum/{cz => no}/__init__.py | 8 +++----
stdnum/{ee/kmkr.py => no/mva.py} | 46 +++++++++++++++++++------------------
stdnum/{pl/nip.py => no/orgnr.py} | 42 ++++++++++++++++-----------------
3 files changed, 49 insertions(+), 47 deletions(-)
copy stdnum/{cz => no}/__init__.py (83%)
copy stdnum/{ee/kmkr.py => no/mva.py} (63%)
copy stdnum/{pl/nip.py => no/orgnr.py} (63%)
hooks/post-receive
--
python-stdnum
--
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/
- python-stdnum branch master updated. 1.0-7-g699b340,
Commits of the python-stdnum project