Radu Boncea 6 jaren geleden
bovenliggende
commit
52b8c1e468
8 gewijzigde bestanden met toevoegingen van 303 en 12 verwijderingen
  1. 0 2
      pyVat/api.py
  2. 0 2
      pyVat/validators/bg.py
  3. 0 1
      pyVat/validators/gb.py
  4. 82 0
      pyVat/validators/ie.py
  5. 57 0
      pyVat/validators/it.py
  6. 73 0
      pyVat/validators/lt.py
  7. 57 0
      pyVat/validators/lu.py
  8. 34 7
      tests/test_validator.py

+ 0 - 2
pyVat/api.py

@@ -134,5 +134,3 @@ class Validator(object):
         validator_klass = load_cc_validator(self.country_code.lower())
         validator = validator_klass()
         return validator.validate(str(self.vat_number))
-
-

+ 0 - 2
pyVat/validators/bg.py

@@ -91,5 +91,3 @@ class Validator(GenericValidator):
             return True
 
         return False
-
-

+ 0 - 1
pyVat/validators/gb.py

@@ -71,4 +71,3 @@ class Validator(GenericValidator):
                 return False
 
         return True
-

+ 82 - 0
pyVat/validators/ie.py

@@ -0,0 +1,82 @@
+# 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.
+
+from __future__ import (
+    unicode_literals,
+    print_function,
+    division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+    """
+    For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+    """
+
+    check_char_mapping = {
+        0: 'W',
+        1: 'A',
+        2: 'B',
+        3: 'C',
+        4: 'D',
+        5: 'E',
+        6: 'F',
+        7: 'G',
+        8: 'H',
+        9: 'I',
+        10: 'J',
+        11: 'K',
+        12: 'L',
+        13: 'M',
+        14: 'N',
+        15: 'O',
+        16: 'P',
+        17: 'Q',
+        18: 'R',
+        19: 'S',
+        20: 'T',
+        21: 'U',
+        22: 'V'
+    }
+
+    def __init__(self):
+        self.regexp = re.compile(r'^((\d{7}[a-z])|(\d[a-z\+\*]\d{5}[a-z]))$', re.IGNORECASE)
+
+    def validate(self, vat_number):
+        if super(Validator, self).validate(vat_number) is False:
+            return False
+
+        vat_number = str(vat_number)
+        checknum = vat_number[7]
+
+        #check for old style - second char sould be a letter
+        try:
+            int(vat_number[1])
+        except:
+            old_style = True
+        else:
+            old_style = False
+
+        if old_style:
+            n = '0' + vat_number[2:7] + vat_number[0]
+            r = self.sum_weights(list(range(8,1,-1)), n) % 23
+        else:
+            r = r = self.sum_weights(list(range(8,1,-1)), vat_number) % 23
+
+        return checknum == Validator.check_char_mapping[r]

+ 57 - 0
pyVat/validators/it.py

@@ -0,0 +1,57 @@
+# 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.
+
+from __future__ import (
+    unicode_literals,
+    print_function,
+    division
+)
+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{11}$')
+
+    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[10])
+
+        c8910 = int(vat_number[7:10])
+        if c8910 not in range(1, 102) and c8910 not in [120, 121, 999, 888]:
+            return False
+
+        s1 = 0
+        for i in range(0,9,2):
+            s1 = s1 + int(vat_number[i])
+
+        s2 = 0
+        for i in range(1,10,2):
+            n = int(vat_number[i])
+            s2 = s2 + int(n/5) + (2 * n) % 10
+
+        checkval = (10 - (s1 + s2) % 10) % 10
+
+        return checknum == checkval

+ 73 - 0
pyVat/validators/lt.py

@@ -0,0 +1,73 @@
+# 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.
+
+from __future__ import (
+    unicode_literals,
+    print_function,
+    division
+)
+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{9})|(\d{12}))$')
+
+    def validate(self, vat_number):
+        if super(Validator, self).validate(vat_number) is False:
+            return False
+
+        vat_number = str(vat_number)
+
+        # Legal entities
+        if len(vat_number) == 9:
+            checknum = int(vat_number[8])
+            if int(vat_number[7]) != 1:
+                return False
+            r1 = self.sum_weights(list(range(1,9)), vat_number) % 11
+            if r1 != 10:
+                checkval = r1
+            else:
+                rng = list(range(3,10)) + [1]
+                r2 = self.sum_weights(rng, vat_number) % 11
+                if r2 == 10:
+                    checkval = 0
+                else:
+                    checkval = r2
+        else:
+            # Temporarily registered taxpayers
+            checknum = int(vat_number[11])
+            if int(vat_number[10]) != 1:
+                return False
+
+            rng = list(range(1,10) + range(1,3))
+            r1 = self.sum_weights(rng, vat_number) % 11
+            if r1 != 10:
+                checkval = r1
+            else:
+                rng = list(range(3, 10) + range(1,5))
+                r2 = self.sum_weights(rng, vat_number) % 11
+                if r2 == 10:
+                    checkval = 0
+                else:
+                    checkval = r2
+        return checknum == checkval

+ 57 - 0
pyVat/validators/lu.py

@@ -0,0 +1,57 @@
+# 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.
+
+from __future__ import (
+    unicode_literals,
+    print_function,
+    division
+)
+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[10])
+
+        c8910 = int(vat_number[7:10])
+        if c8910 not in range(1, 102) and c8910 not in [120, 121, 999, 888]:
+            return False
+
+        s1 = 0
+        for i in range(0,9,2):
+            s1 = s1 + int(vat_number[i])
+
+        s2 = 0
+        for i in range(1,10,2):
+            n = int(vat_number[i])
+            s2 = s2 + int(n/5) + (2 * n) % 10
+
+        checkval = (10 - (s1 + s2) % 10) % 10
+
+        return checknum == checkval

+ 34 - 7
tests/test_validator.py

@@ -265,12 +265,39 @@ class TestValidator(unittest.TestCase):
         validator = Validator('GB434031494')
         self.assertTrue(validator.validate())
 
+
+    def test_ie(self):
+        # old style format
+        validator = Validator('IE8Z49289F')
+        self.assertTrue(validator.validate())
+        self.assertEqual(validator.country_code, 'IE')
+        validator = Validator('IE26287395')
+        self.assertFalse(validator.validate())
+
+        # new style
+        validator = Validator('IE3628739L')
+        self.assertTrue(validator.validate())
+
+    def test_it(self):
+        validator = Validator('IT00000010215')
+        self.assertTrue(validator.validate())
+        self.assertEqual(validator.country_code, 'IT')
+        validator = Validator('IT00000017775')
+        self.assertFalse(validator.validate())
+
+    def test_lt(self):
+        #juridical entities
+        validator = Validator('LT213179412')
+        self.assertTrue(validator.validate())
+        self.assertEqual(validator.country_code, 'LT')
+        validator = Validator('LT213179422')
+        self.assertFalse(validator.validate())
+
+        # Temporarily registered taxpayers
+        validator = Validator('LT290061371314')
+        self.assertTrue(validator.validate())
+        validator = Validator('LT290061371324')
+        self.assertFalse(validator.validate())
+
 if __name__ == '__main__':
     unittest.main()
-
-#
-#
-#
-# validator = Validator()
-#
-# print (validator.validate(36804251))