lists.arthurdejong.org
RSS feed

python-stdnum commit: r166 - python-stdnum/stdnum/fr

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

python-stdnum commit: r166 - python-stdnum/stdnum/fr



Author: arthur
Date: Sun Feb 26 12:36:34 2012
New Revision: 166
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=166&view=revision

Log:
add a to_vta() function to the stdnum.fr.siren module

Modified:
   python-stdnum/stdnum/fr/siren.py

Modified: python-stdnum/stdnum/fr/siren.py
==============================================================================
--- python-stdnum/stdnum/fr/siren.py    Sun Feb 26 12:10:38 2012        (r165)
+++ python-stdnum/stdnum/fr/siren.py    Sun Feb 26 12:36:34 2012        (r166)
@@ -30,12 +30,20 @@
 True
 >>> is_valid('404833047')
 False
+>>> to_tva('443 121 975')
+'46 443 121 975'
 """
 
 from stdnum.util import clean
 from stdnum import luhn
 
 
+# An online validation function is available but it does not provide an
+# automated entry point, has usage restrictions and seems to require
+# attribution to the service for any results used.
+# http://avis-situation-sirene.insee.fr/
+
+
 def compact(number):
     """Convert the number to the minimal representation. This strips the
     number of any valid separators and removes surrounding whitespace."""
@@ -50,3 +58,14 @@
     except:
         return False
     return len(number) == 9 and number.isdigit() and luhn.is_valid(number)
+
+
+def to_tva(number):
+    """Return a TVA that prepends the two extra check digits to the SIREN."""
+    # note that this always returns numeric check digits
+    # it is unclean when the alphabetic ones are used
+    return '%02d%s%s' % (
+        int(compact(number) + '12') % 97,
+        ' ' if ' ' in number else '',
+        number
+    )
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/