borni-dhifi / vatnumber

Automatically exported from code.google.com/p/vatnumber
GNU General Public License v3.0
0 stars 0 forks source link

Mexican VAT verification is missing in vatnumber library #16

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hello, 

What steps will reproduce the problem?
1. Mexican VAT verification is missing in vatnumber library.

Please provide any additional information below.
Currently We are using our own validation function for Maxico, but as we are 
going to use vatnumber library for all vat verification will you please add the 
same.

Here is the link which suggest the syntax on maxican vat numbers.
http://en.wikipedia.org/wiki/Vat_number

Thanks,
Purnendu Singh(OpenERP)

Original issue reported on code.google.com by micku1...@gmail.com on 6 Jul 2011 at 9:34

GoogleCodeExporter commented 8 years ago

Original comment by cedric.krier@b2ck.com on 6 Jul 2011 at 9:46

GoogleCodeExporter commented 8 years ago
The wikipedia doesn't provide a real validation.

Original comment by cedric.krier@b2ck.com on 6 Jul 2011 at 9:47

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
In mexico, VAT numbers format differ between people and companies. The last 
posted patch was for a physical person only. This one extends it to include 
also companies:

--- __init__.py.bak     2012-04-15 18:24:08.335900949 -0500
+++ __init__.py 2012-04-15 19:07:06.646425437 -0500
@@ -875,6 +875,18 @@
         return False
     return True

+def check_vat_mx(vat):
+    '''
+    Check Mexico VAT number.
+    '''
+    if len(vat) in (10,13):
+        try:
+            int(vat[4:10])
+        except ValueError:
+            return False
+        return True
+
+    elif len(vat) == 12:
+        try:
+            int(vat[3:9])
+        except ValueError:
+            return False
+        return True
+
+    return False
+
 def check_vat_nl(vat):
     '''
     Check Netherlands VAT number.

And this one for test.py:

--- tests.py    2012-04-15 19:05:47.000115920 -0500
+++ tests.py.bak    2012-04-15 19:09:57.632021763 -0500
@@ -156,6 +156,8 @@
     ('LV', '41234567891', True),
     ('LV', '15066312345', True),
     ('MT', '12345634', True),
+    ('MX', 'ABCD123456', True),
+    ('MX', 'ABCD123456AB4', True),
+    ('MX', 'ABC123456AB4', True),
     ('NL', '123456782B90', True),
     ('PL', '1234567883', True),
     ('PT', '123456789', True),

Original comment by rsepulv...@gmail.com on 16 Apr 2012 at 12:21

GoogleCodeExporter commented 8 years ago
It is strange as it doesn't follow the wikipedia page.
Have you some more documentation about it?
Otherwise attach a patch to the issue created with "hg export"

Original comment by cedric.krier@b2ck.com on 16 Apr 2012 at 6:52

GoogleCodeExporter commented 8 years ago
Here is a link describing it: (spanish) 
http://losimpuestos.com.mx/rfc-homoclave/
(I've tried to use google translate, but the order on some examples reverses.)

In Mexico the VAT number is called RFC.

In short, It is composed of 4 letters that are grabbed from your lastnames (in 
mexico there are 2 lastnames) and your first name. After that it has 6 digits 
being the year, month and day of your birthday, and last (optional, because you 
still have a VAT number even if you don't ask for one) a 'key' called 
'homoclave' in spanish that is provided by the government that is 3 characters 
long (can be numbers or letters or both.)

In case of a buissiness, the starting characters are 3 instead of 4.

Being this, the validation practically can only look for the 6 digits from your 
birthday, and it can be 10 digits (without 'key'), 13 digits (with 'key') and 
12 digits (for bussinesses).

Also, from the wikipedia article, the spaces between the code are for being 
easier to read, but not required (or even used). In every place that your VAT 
number is required, no spaces are allowed.

Original comment by rsepulv...@gmail.com on 16 Apr 2012 at 8:19

GoogleCodeExporter commented 8 years ago
Here is the output of hg export:

# HG changeset patch
# User Rafael Sepulveda <rsepulveda@gmail.com>
# Date 1334565007 18000
# Node ID 4970b6ab3f9fb755d7b703cca737afdaa43c4d80
# Parent  8e8d3a4430e08d55c32c683e92a9d16e0a6a7360
Add support to Mexico VAT number (spanish: RFC)

diff -r 8e8d3a4430e0 -r 4970b6ab3f9f vatnumber/__init__.py
--- a/vatnumber/__init__.py     Tue Nov 15 17:02:45 2011 +0100
+++ b/vatnumber/__init__.py     Mon Apr 16 03:30:07 2012 -0500
@@ -922,6 +922,27 @@
     return True

+def check_vat_mx(vat):
+    '''
+    Check Mexico VAT number.
+    '''
+    if len(vat) in (10,13):
+        try:
+            int(vat[4:10])
+        except ValueError:
+            return False
+        return True
+
+    elif len(vat) == 12:
+        try:
+            int(vat[3:9])
+        except ValueError:
+            return False
+        return True
+
+    return False
+
+
 def check_vat_nl(vat):
     '''
     Check Netherlands VAT number.
diff -r 8e8d3a4430e0 -r 4970b6ab3f9f vatnumber/tests.py
--- a/vatnumber/tests.py        Tue Nov 15 17:02:45 2011 +0100
+++ b/vatnumber/tests.py        Mon Apr 16 03:30:07 2012 -0500
@@ -158,6 +158,9 @@
     ('LV', '41234567891', True),
     ('LV', '15066312345', True),
     ('MT', '12345634', True),
+    ('MX', 'ABCD123456', True),
+    ('MX', 'ABCD123456AB4', True),
+    ('MX', 'ABC123456AB4', True),
     ('NL', '123456782B90', True),
     ('PL', '1234567883', True),
     ('PT', '123456789', True),

Original comment by rsepulv...@gmail.com on 16 Apr 2012 at 8:36

GoogleCodeExporter commented 8 years ago
So the validation could check at least that YYMMDD are valid.

Original comment by cedric.krier@b2ck.com on 16 Apr 2012 at 8:58

GoogleCodeExporter commented 8 years ago
Actually the patch checks the size of the string and that the correct part of 
YYMMDD are integers. To check the first part you need the complete name of the 
person/buissiness (impractical) and the seccond is imposible because is 
assigned by the government.

Original comment by rsepulv...@gmail.com on 16 Apr 2012 at 9:08

GoogleCodeExporter commented 8 years ago
We could use this patch (over the previous one) to use time validation instead 
of only check if they are only integers:

# HG changeset patch
# User Rafael Sepulveda <rsepulveda@gmail.com>
# Date 1335140849 18000
# Node ID 71446cad0566c5f0daea616d21ec3902467b6b63
# Parent  4970b6ab3f9fb755d7b703cca737afdaa43c4d80
Use time validation in Mexico VAT number.

diff -r 4970b6ab3f9f -r 71446cad0566 vatnumber/__init__.py
--- a/vatnumber/__init__.py Mon Apr 16 03:30:07 2012 -0500
+++ b/vatnumber/__init__.py Sun Apr 22 19:27:29 2012 -0500
@@ -928,14 +928,16 @@
     '''
     if len(vat) in (10,13):
         try:
-            int(vat[4:10])
+            import time
+            time.strptime(vat[4:10],"%y%m%d")
         except ValueError:
             return False
         return True

     elif len(vat) == 12:
         try:
-            int(vat[3:9])
+            import time
+            time.strptime(vat[3:9],"%y%m%d")
         except ValueError:
             return False
         return True

Original comment by rsepulv...@gmail.com on 23 Apr 2012 at 12:31

GoogleCodeExporter commented 8 years ago
If that patch is ok using 'time', then this is a simpler version (applied over 
the last patch :)

# HG changeset patch
# User Rafael Sepulveda <rsepulveda@gmail.com>
# Date 1335141366 18000
# Node ID c06f9102e59b0b69b175a625f15b7717777a12f3
# Parent  71446cad0566c5f0daea616d21ec3902467b6b63
Simpler time checking to Mexico VAT number.

diff -r 71446cad0566 -r c06f9102e59b vatnumber/__init__.py
--- a/vatnumber/__init__.py Sun Apr 22 19:27:29 2012 -0500
+++ b/vatnumber/__init__.py Sun Apr 22 19:36:06 2012 -0500
@@ -927,22 +927,18 @@
     Check Mexico VAT number.
     '''
     if len(vat) in (10,13):
-        try:
-            import time
-            time.strptime(vat[4:10],"%y%m%d")
-        except ValueError:
-            return False
-        return True
+        check_date = vat[4:10]
+    elif len(vat) == 12:
+        check_date = vat[3:9]
+    else:
+        return False

-    elif len(vat) == 12:
-        try:
-            import time
-            time.strptime(vat[3:9],"%y%m%d")
-        except ValueError:
-            return False
-        return True
-
-    return False
+    try:
+        import time
+        time.strptime(check_date,"%y%m%d")
+    except ValueError:
+        return False
+    return True

 def check_vat_nl(vat):

Original comment by rsepulv...@gmail.com on 23 Apr 2012 at 12:42

GoogleCodeExporter commented 8 years ago
Could you upload your patch on codereview https://codereview.appspot.com/

Original comment by cedric.krier@b2ck.com on 23 Apr 2012 at 7:00

GoogleCodeExporter commented 8 years ago
I uploaded in https://codereview.appspot.com/6105052/

Original comment by rsepulv...@gmail.com on 23 Apr 2012 at 2:06

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I don't know how to update the code in codereview, so I opened a new issue with 
the corrections you made. https://codereview.appspot.com/6112046/

Original comment by rsepulv...@gmail.com on 24 Apr 2012 at 7:00

GoogleCodeExporter commented 8 years ago
No, update the first one, I will not review others.
RTFM!

Original comment by cedric.krier@b2ck.com on 24 Apr 2012 at 7:28

GoogleCodeExporter commented 8 years ago
Ok, you're right.

I've already closed the new issue and updated the first one. Pretty easy after 
RTFM. :)

Original comment by rsepulv...@gmail.com on 24 Apr 2012 at 7:48

GoogleCodeExporter commented 8 years ago
http://codereview.tryton.org/456002/ new method!

Original comment by zodman@gmail.com on 30 Jul 2012 at 9:18

GoogleCodeExporter commented 8 years ago
@zodman 
Why are you using the tryton codereview instead of the appspot one?

Original comment by cedric.krier@b2ck.com on 30 Jul 2012 at 9:27

GoogleCodeExporter commented 8 years ago
Sorry @ced i will delete it. and create a new one.

Original comment by zodman@gmail.com on 31 Jul 2012 at 7:05

GoogleCodeExporter commented 8 years ago
i remove the tryton codereview and added the new

http://codereview.appspot.com/6445067/

Original comment by zodman@gmail.com on 31 Jul 2012 at 8:19

GoogleCodeExporter commented 8 years ago
my second try.

http://codereview.appspot.com/13373047

Original comment by zodman@gmail.com on 31 Aug 2013 at 7:43

GoogleCodeExporter commented 8 years ago
vatnumber uses now python-stdnum, so new validation should be first proposed 
there.

Original comment by cedric.krier@b2ck.com on 3 Apr 2014 at 7:40