python-stdnum branch master updated. 1.19-7-g9c7c669
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.19-7-g9c7c669
- 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, python-stdnum-commits [at] lists.arthurdejong.org
- Subject: python-stdnum branch master updated. 1.19-7-g9c7c669
- Date: Sun, 25 Feb 2024 17:32:29 +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 9c7c669ece1491e7fd697f2184ad9b7185be59b2 (commit)
from 1e412ee066afaa0861b4885604aa6106a3c4c879 (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=9c7c669ece1491e7fd697f2184ad9b7185be59b2
commit 9c7c669ece1491e7fd697f2184ad9b7185be59b2
Author: Kevin Dagostino <kevin@tonkworks.com>
Date: Fri Dec 15 12:59:26 2023 -0500
Imporve French NIF validation (checksum)
The last 3 digits are a checksum. % 511
https://ec.europa.eu/taxation_customs/tin/specs/FS-TIN%20Algorithms-Public.docx
Closes https://github.com/arthurdejong/python-stdnum/pull/426
diff --git a/stdnum/fr/nif.py b/stdnum/fr/nif.py
index 4d57e4e..d043674 100644
--- a/stdnum/fr/nif.py
+++ b/stdnum/fr/nif.py
@@ -30,8 +30,12 @@ More information:
* https://ec.europa.eu/taxation_customs/tin/tinByCountry.html
* https://fr.wikipedia.org/wiki/Numéro_d%27Immatriculation_Fiscale#France
->>> validate('0701987765432')
-'0701987765432'
+>>> validate('3023217600053')
+'3023217600053'
+>>> validate('3023217600054')
+Traceback (most recent call last):
+ ...
+InvalidChecksum: ...
>>> validate('070198776543')
Traceback (most recent call last):
...
@@ -40,8 +44,8 @@ InvalidLength: ...
Traceback (most recent call last):
...
InvalidComponent: ...
->>> format('0701987765432')
-'07 01 987 765 432'
+>>> format('3023217600053')
+'30 23 217 600 053'
"""
from stdnum.exceptions import *
@@ -54,6 +58,11 @@ def compact(number):
return clean(number, ' ').strip()
+def calc_check_digits(number):
+ """Calculate the check digits for the number."""
+ return '%03d' % (int(number[:10]) % 511)
+
+
def validate(number):
"""Check if the number provided is a valid NIF."""
number = compact(number)
@@ -63,6 +72,8 @@ def validate(number):
raise InvalidComponent()
if len(number) != 13:
raise InvalidLength()
+ if calc_check_digits(number) != number[-3:]:
+ raise InvalidChecksum()
return number
-----------------------------------------------------------------------
Summary of changes:
stdnum/fr/nif.py | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
hooks/post-receive
--
python-stdnum
- python-stdnum branch master updated. 1.19-7-g9c7c669,
Commits of the python-stdnum project