lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.17-8-g73f5e3a

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.17-8-g73f5e3a



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  73f5e3a864915e9f3f2b01683ab9b192b4217e46 (commit)
      from  27c7c74dfb5a15038b405d37fd7214b2900ec843 (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=73f5e3a864915e9f3f2b01683ab9b192b4217e46

commit 73f5e3a864915e9f3f2b01683ab9b192b4217e46
Author: Cédric Krier <ced@b2ck.com>
Date:   Mon Mar 7 14:21:55 2022 +0100

    Support special validation of La Post SIRET
    
    See 
https://fr.wikipedia.org/wiki/Système_d'identification_du_répertoire_des_établissements#Exceptions_pour_le_groupe_La_Poste
    
    Closes https://github.com/arthurdejong/python-stdnum/pull/293
    Closes https://github.com/arthurdejong/python-stdnum/issues/291

diff --git a/stdnum/fr/siret.py b/stdnum/fr/siret.py
index 7c4e0f5..7e728f7 100644
--- a/stdnum/fr/siret.py
+++ b/stdnum/fr/siret.py
@@ -22,7 +22,12 @@
 
 The SIRET (Système d'Identification du Répertoire des ETablissements)
 is a 14 digit number used to identify French companies' establishments
-and facilities. The Luhn checksum is used to validate the numbers.
+and facilities. The Luhn checksum is used to validate the numbers (except
+for La Poste).
+
+More information:
+
+* 
https://fr.wikipedia.org/wiki/Système_d'identification_du_répertoire_des_établissements
 
 >>> validate('73282932000074')
 '73282932000074'
@@ -62,7 +67,13 @@ def validate(number):
         raise InvalidFormat()
     if len(number) != 14:
         raise InvalidLength()
-    luhn.validate(number)
+    # La Poste SIRET (except the head office) do not use the Luhn checksum
+    # but the sum of digits must be a multiple of 5
+    if number.startswith('356000000') and number != '35600000000048':
+        if sum(map(int, number)) % 5 != 0:
+            raise InvalidChecksum()
+    else:
+        luhn.validate(number)
     siren.validate(number[:9])
     return number
 
diff --git a/tests/test_fr_siret.doctest b/tests/test_fr_siret.doctest
index 699ac33..a7f2f69 100644
--- a/tests/test_fr_siret.doctest
+++ b/tests/test_fr_siret.doctest
@@ -24,6 +24,21 @@ This file contains more detailed doctests for the 
stdnum.fr.siret module.
 >>> from stdnum.exceptions import *
 
 
+La Poste SIRET does not use the Luhn checksum but the sum of digits must be a
+multiple of 5.
+
+>>> siret.validate('356 000 000 09075')
+'35600000009075'
+>>> siret.validate('35600000000048')
+'35600000000048'
+>>> siret.validate('35600000049837')
+'35600000049837'
+>>> siret.validate('35600000049838')
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
+
+
 These have been found online and should all be valid numbers.
 
 >>> numbers = '''

-----------------------------------------------------------------------

Summary of changes:
 stdnum/fr/siret.py          | 15 +++++++++++++--
 tests/test_fr_siret.doctest | 15 +++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)


hooks/post-receive
-- 
python-stdnum