python-stdnum branch master updated. 1.5-5-gc957318
[Date Prev][
Date Next]
[Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.5-5-gc957318
- 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.5-5-gc957318
- Date: Sat, 25 Mar 2017 11:49:18 +0100 (CET)
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 c957318aacacf6496e7fef6198f6b9e791552b70 (commit)
from 5b4385732f6b7d7b5959e742881e20d63ec58183 (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 -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=c957318aacacf6496e7fef6198f6b9e791552b70
commit c957318aacacf6496e7fef6198f6b9e791552b70
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Sun Mar 19 15:28:27 2017 +0100
Add support for Monaco VAT number
The number uses the French TVA number but, unlike normal French VAT
numbers, they are not valid French SIREN numbers.
See https://github.com/arthurdejong/python-stdnum/issues/46
diff --git a/stdnum/fr/tva.py b/stdnum/fr/tva.py
index c82ad82..bb46fed 100644
--- a/stdnum/fr/tva.py
+++ b/stdnum/fr/tva.py
@@ -1,7 +1,7 @@
# tva.py - functions for handling French TVA numbers
# coding: utf-8
#
-# Copyright (C) 2012-2015 Arthur de Jong
+# Copyright (C) 2012-2017 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
@@ -67,9 +67,13 @@ def validate(number):
number = compact(number)
if not all(x in _alphabet for x in number[:2]):
raise InvalidFormat()
+ if not number[2:].isdigit():
+ raise InvalidFormat()
if len(number) != 11:
raise InvalidLength()
- siren.validate(number[2:])
+ if number[2:5] != '000':
+ # numbers from Monaco are valid TVA but not SIREN
+ siren.validate(number[2:])
if number.isdigit():
# all-numeric digits
if int(number[:2]) != (int(number[2:] + '12') % 97):
diff --git a/stdnum/mc/__init__.py b/stdnum/mc/__init__.py
new file mode 100644
index 0000000..835d258
--- /dev/null
+++ b/stdnum/mc/__init__.py
@@ -0,0 +1,24 @@
+# __init__.py - collection of Monacan numbers
+# coding: utf-8
+#
+# Copyright (C) 2017 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
+
+"""Collection of Monacan numbers."""
+
+# provide vat as an alias
+from stdnum.mc import tva as vat
diff --git a/stdnum/mc/tva.py b/stdnum/mc/tva.py
new file mode 100644
index 0000000..dacf803
--- /dev/null
+++ b/stdnum/mc/tva.py
@@ -0,0 +1,63 @@
+# tva.py - functions for handling Monacan TVA numbers
+# coding: utf-8
+#
+# Copyright (C) 2017 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
+
+"""n° TVA (taxe sur la valeur ajoutée, Monacan VAT number).
+
+For VAT purposes Monaco is treated as territory of France. The number is
+also validated the same as the French TVA, except that it is not based on
+a French SIREN.
+
+>>> compact('53 0000 04605')
+'FR53000004605'
+>>> validate('53 0000 04605')
+'FR53000004605'
+>>> validate('FR 61 954 506 077') # French numbers are invalid
+Traceback (most recent call last):
+ ...
+InvalidComponent: ...
+"""
+
+from stdnum.exceptions import *
+from stdnum.util import clean
+from stdnum.fr import tva
+
+
+def compact(number):
+ """Convert the number to the minimal representation. This strips the
+ number of any valid separators and removes surrounding whitespace."""
+ return 'FR' + tva.compact(number)
+
+
+def validate(number):
+ """Checks to see if the number provided is a valid VAT number. This
+ checks the length, formatting and check digit."""
+ number = tva.validate(number)
+ if number[2:5] != '000':
+ raise InvalidComponent()
+ return 'FR' + 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:
+ return bool(validate(number))
+ except ValidationError:
+ return False
diff --git a/tests/test_eu_vat.doctest b/tests/test_eu_vat.doctest
index ce10efd..a578d67 100644
--- a/tests/test_eu_vat.doctest
+++ b/tests/test_eu_vat.doctest
@@ -1,6 +1,6 @@
test_eu_vat.doctest - more detailed doctests for the stdnum.eu.vat module
-Copyright (C) 2012-2015 Arthur de Jong
+Copyright (C) 2012-2017 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
@@ -313,6 +313,28 @@ These have been found online and should all be valid
numbers.
... Fr 96 631 620 572
... fr 71383076817
...
+... FR16000063601
+... FR23000047372
+... FR26000040583
+... FR28000113851
+... FR30000017854
+... FR32000000330
+... FR36000006022
+... FR40000066034
+... FR43000020445
+... FR48000052489
+... FR54000065101
+... FR64000063908
+... FR65000100833
+... FR79000030642
+... FR83000065143
+... FR83000113158
+... FR84000082668
+... FR87000018746
+... FR88000008820
+... FR88000053537
+... FR96000110899
+...
... GB 002 4257 28
... GB 003232345
... GB 100 1950 75
@@ -864,6 +886,8 @@ These numbers should be mostly valid except that they have
the wrong length.
...
... ES B-583784312
...
+... FR000076090
+...
... NL006866304B021
...
... SE 55643359201
-----------------------------------------------------------------------
Summary of changes:
stdnum/fr/tva.py | 8 ++++++--
stdnum/{fr => mc}/__init__.py | 8 ++++----
stdnum/{se/vat.py => mc/tva.py} | 38 ++++++++++++++++++--------------------
tests/test_eu_vat.doctest | 26 +++++++++++++++++++++++++-
4 files changed, 53 insertions(+), 27 deletions(-)
copy stdnum/{fr => mc}/__init__.py (83%)
copy stdnum/{se/vat.py => mc/tva.py} (64%)
hooks/post-receive
--
python-stdnum
--
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
https://lists.arthurdejong.org/python-stdnum-commits/
- python-stdnum branch master updated. 1.5-5-gc957318,
Commits of the python-stdnum project