Explorar el Código

Finland validator and started French

Radu Boncea hace 6 años
padre
commit
a455eaa504
Se han modificado 4 ficheros con 169 adiciones y 1 borrados
  1. 1 1
      pyVat/api.py
  2. 44 0
      pyVat/validators/fi.py
  3. 96 0
      pyVat/validators/fr.py
  4. 28 0
      tests/test_validator.py

+ 1 - 1
pyVat/api.py

@@ -32,7 +32,7 @@ VAT_NUMBER_REGEXPS = {
     'EE': re.compile(r'^\d{9}$'),
     'ES': re.compile(r'^[\da-z]\d{7}[\da-z]$', re.IGNORECASE),
     'FI': re.compile(r'^\d{8}$'),
-    'FR': re.compile(r'^[\da-hj-np-z]{2}\d{9}$', re.IGNORECASE),
+    'FR': re.compile(r'^[\da-z]{2}\d{9}$', re.IGNORECASE),
     'GB': re.compile(r'^((\d{9})|(\d{12})|(GD\d{3})|(HA\d{3}))$',
                      re.IGNORECASE),
     'GR': re.compile(r'^\d{9}$'),

+ 44 - 0
pyVat/validators/fi.py

@@ -0,0 +1,44 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+    """
+    For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+    """
+    def __init__(self):
+        self.regexp = re.compile(r'^\d{8}$')
+
+    def validate(self, vat_number):
+        if super(Validator, self).validate(vat_number) is False:
+            return False
+
+        vat_number = str(vat_number)
+
+        checknum = int(vat_number[7])
+
+        r = 11 - self.sum_weights([7,9,10,5,8,4,2], vat_number) % 11
+        if r == 0:
+            return False
+        elif r == 11:
+            if checknum != 0:
+                return False
+        else:
+            return checknum == r

+ 96 - 0
pyVat/validators/fr.py

@@ -0,0 +1,96 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+import re
+import sys
+from .generic import GenericValidator
+
+PY_3_OR_HIGHER = sys.version_info >= (3, 0)
+
+class Validator(GenericValidator):
+    """
+    For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+    """
+    check_caracter_mapping = {
+        0: '0',
+        1: '1',
+        2: '2',
+        3: '3',
+        4: '4',
+        5: '5',
+        6: '6',
+        7: '7',
+        8: '8',
+        9: '9',
+        10: 'A',
+        11: 'B',
+        12: 'C',
+        13: 'D',
+        14: 'E',
+        15: 'F',
+        16: 'G',
+        17: 'H',
+        18: 'J',
+        19: 'K',
+        20: 'L',
+        21: 'M',
+        22: 'N',
+        23: 'P',
+        24: 'Q',
+        25: 'R',
+        26: 'S',
+        27: 'T',
+        28: 'U',
+        29: 'V',
+        30: 'W',
+        31: 'X',
+        32: 'Y',
+        33: 'Z'
+
+    }
+
+    def __init__(self):
+        self.regexp = re.compile(r'^[\da-z]{2}\d{9}$', re.IGNORECASE)
+
+    def validate(self, vat_number):
+        if super(Validator, self).validate(vat_number) is False:
+            return False
+
+        vat_number = str(vat_number)
+
+        try:
+            int(vat_number)
+        except:
+            new_style = True
+        else:
+            new_style = False
+
+        if new_style is False:
+            checkval = int(vat_number[2:] + '12') % 97
+            return int(vat_number[:2]) == checkval
+        else:
+            try:
+                c1 = int(vat_number[0])
+            except:
+                c1_is_numeric = False
+            else:
+                c1_is_numeric = True
+
+            inv_ccm = 
+
+            #if c1_is_numeric:
+                # c2 must be numeric as otherwise would have been caught in old style

+ 28 - 0
tests/test_validator.py

@@ -218,6 +218,34 @@ class TestValidator(unittest.TestCase):
         validator = Validator('ESB30034573')
         self.assertTrue(validator.validate())
 
+    def test_fi(self):
+        validator = Validator('fi09853608')
+        self.assertTrue(validator.validate())
+        self.assertEqual(validator.country_code, 'FI')
+
+        validator = Validator('FI09853607')
+        self.assertFalse(validator.validate())
+
+    def test_fr(self):
+        # old style
+        validator = Validator('FR00300076965')
+        self.assertTrue(validator.validate())
+        self.assertEqual(validator.country_code, 'FR')
+        validator = Validator('FR06300076967')
+        self.assertTrue(validator.validate())
+        validator = Validator('FR46441049376')
+        self.assertTrue(validator.validate())
+        validator = Validator('Fr28316607779')
+        self.assertTrue(validator.validate())
+
+        validator = Validator('FR00300076964')
+        self.assertFalse(validator.validate())
+
+        #  new style
+        #validator = Validator('FR02300076965')
+        #self.assertTrue(validator.validate())
+
+
 if __name__ == '__main__':
     unittest.main()