1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 # Copyright (C) 2008-2009 B2CK, Cedric Krier, Bertrand Chenal (the methods "check_vat_[a-z]{2}"
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
24 from osv import osv, fields
25 from tools.translate import _
26 from tools.misc import ustr
31 'be': 'BE0477472701', 'at': 'ATU12345675',
32 'bg': 'BG1234567892', 'cy': 'CY12345678F',
33 'cz': 'CZ12345679', 'de': 'DE123456788',
34 'dk': 'DK12345674', 'ee': 'EE123456780',
35 'es': 'ESA12345674', 'fi': 'FI12345671',
36 'fr': 'FR32123456789', 'gb': 'GB123456782',
37 'gr': 'GR12345670', 'hu': 'HU12345676',
38 'ie': 'IE1234567T', 'it': 'IT12345670017',
39 'lt': 'LT123456715', 'lu': 'LU12345613',
40 'lv': 'LV41234567891', 'mt': 'MT12345634',
41 'nl': 'NL123456782B90', 'pl': 'PL1234567883',
42 'pt': 'PT123456789', 'ro': 'RO1234567897',
43 'se': 'SE123456789701', 'si': 'SI12345679',
44 'sk': 'SK0012345675', 'el': 'EL12345670',
45 'mx': 'MXABCD831230T1B', 'hr': 'HR01234567896'
50 """Sum each digits of the multiplication of i and j."""
51 return reduce(lambda x, y: x + int(y), str(i*j), 0)
53 class res_partner(osv.osv):
54 _inherit = 'res.partner'
56 def _split_vat(self, vat):
57 vat_country, vat_number = vat[:2].lower(), vat[2:].replace(' ', '')
58 return vat_country, vat_number
60 def check_vat(self, cr, uid, ids, context=None):
62 Check the VAT number depending of the country.
63 http://sima-pc.com/nif.php
65 country_obj = self.pool.get('res.country')
66 for partner in self.browse(cr, uid, ids, context=context):
69 vat_country, vat_number = self._split_vat(partner.vat)
70 if not hasattr(self, 'check_vat_' + vat_country):
71 #We didn't find the validation method for the country code. If that country code can be found in openerp, this means that it is a valid country code
72 #and we simply didn't have implemented that function. In that case we continue.
73 if country_obj.search(cr, uid, [('code', 'ilike', vat_country)], context=context):
75 #Otherwise, it means that the country code isn't valid and we return False.
77 check = getattr(self, 'check_vat_' + vat_country)
78 if not check(vat_number):
82 def vat_change(self, cr, uid, ids, value, context=None):
83 return {'value': {'vat_subjected': bool(value)}}
86 'vat_subjected': fields.boolean('VAT Legal Statement', help="Check this box if the partner is subjected to the VAT. It will be used for the VAT legal statement.")
89 def _construct_constraint_msg(self, cr, uid, ids, context=None):
90 def default_vat_check(cn, vn):
91 # by default, a VAT number is valid if:
92 # it starts with 2 letters
93 # has more than 3 characters
94 return cn[0] in string.ascii_lowercase and cn[1] in string.ascii_lowercase
95 vat_country, vat_number = self._split_vat(self.browse(cr, uid, ids)[0].vat)
96 if default_vat_check(vat_country, vat_number):
97 vat_no = vat_country in _ref_vat and _ref_vat[vat_country] or 'Country Code + Vat Number'
98 return _('The Vat does not seems to be correct. You should have entered something like this %s'), (vat_no)
99 return _('The VAT is invalid, It should begin with the country code'), ()
101 _constraints = [(check_vat, _construct_constraint_msg, ["vat"])]
103 # code from the following methods come from Tryton (B2CK)
104 # http://www.tryton.org/hgwebdir.cgi/modules/relationship/file/544d1de586d9/party.py
105 def check_vat_at(self, vat):
107 Check Austria VAT number.
118 sum = int(num[0]) + mult_add(2, int(num[1])) + \
119 int(num[2]) + mult_add(2, int(num[3])) + \
120 int(num[4]) + mult_add(2, int(num[5])) + \
122 check = 10 - ((sum + 4) % 10)
125 if int(vat[-1:]) != check:
129 def check_vat_be(self, vat):
131 Check Belgium VAT number.
139 if int(vat[-2:]) != \
140 97 - (int(vat[:8]) % 97):
144 def check_vat_bg(self, vat):
146 Check Bulgaria VAT number.
148 if len(vat) not in [9,10]:
154 if int(vat[0]) in (2, 3) and \
157 sum = 4 * int(vat[0]) + 3 * int(vat[1]) + 2 * int(vat[2]) + \
158 7 * int(vat[3]) + 6 * int(vat[4]) + 5 * int(vat[5]) + \
159 4 * int(vat[6]) + 3 * int(vat[7]) + 2 * int(vat[8])
160 check = 11 - (sum % 11)
165 def check_vat_cy(self, vat):
167 Check Cyprus VAT number.
211 sum = n0 + n1 + n2 + n3 + n4 + n5 + n6 + n7
212 check = chr(sum % 26 + 65)
217 def check_vat_cz(self, vat):
219 Check Czech Republic VAT number.
221 if len(vat) not in (8, 9, 10):
229 if int(vat[0]) not in (0, 1, 2, 3, 4, 5, 6, 7, 8):
231 sum = 8 * int(vat[0]) + 7 * int(vat[1]) + 6 * int(vat[2]) + \
232 5 * int(vat[3]) + 4 * int(vat[4]) + 3 * int(vat[5]) + \
234 check = 11 - (sum % 11)
239 if check != int(vat[7]):
241 elif len(vat) == 9 and int(vat[0]) == 6:
242 sum = 8 * int(vat[1]) + 7 * int(vat[2]) + 6 * int(vat[3]) + \
243 5 * int(vat[4]) + 4 * int(vat[5]) + 3 * int(vat[6]) + \
245 check = 9 - ((11 - (sum % 11)) % 10)
246 if check != int(vat[8]):
249 if int(vat[0:2]) > 53 and int(vat[0:2]) < 80:
251 if int(vat[2:4]) < 1:
253 if int(vat[2:4]) > 12 and int(vat[2:4]) < 51:
255 if int(vat[2:4]) > 62:
257 if int(vat[2:4]) in (2, 52) and int(vat[0:2]) % 4 > 0:
258 if int(vat[4:6]) < 1:
260 if int(vat[4:6]) > 28:
262 if int(vat[2:4]) in (2, 52) and int(vat[0:2]) % 4 == 0:
263 if int(vat[4:6]) < 1:
265 if int(vat[4:6]) > 29:
267 if int(vat[2:4]) in (4, 6, 9, 11, 54, 56, 59, 61):
268 if int(vat[4:6]) < 1:
270 if int(vat[4:6]) > 30:
272 if int(vat[2:4]) in (1, 3, 5, 7, 8, 10, 12, 51,
273 53, 55, 57, 58, 60, 62):
274 if int(vat[4:6]) < 1:
276 if int(vat[4:6]) > 31:
279 if int(vat[0:2]) < 54:
281 if int(vat[2:4]) < 1:
283 if int(vat[2:4]) > 12 and int(vat[2:4]) < 51:
285 if int(vat[2:4]) > 62:
287 if int(vat[2:4]) in (2, 52) and int(vat[0:2]) % 4 > 0:
288 if int(vat[4:6]) < 1:
290 if int(vat[4:6]) > 28:
292 if int(vat[2:4]) in (2, 52) and int(vat[0:2]) % 4 == 0:
293 if int(vat[4:6]) < 1:
295 if int(vat[4:6]) > 29:
297 if int(vat[2:4]) in (4, 6, 9, 11, 54, 56, 59, 61):
298 if int(vat[4:6]) < 1:
300 if int(vat[4:6]) > 30:
302 if int(vat[2:4]) in (1, 3, 5, 7, 8, 10, 12, 51,
303 53, 55, 57, 58, 60, 62):
304 if int(vat[4:6]) < 1:
306 if int(vat[4:6]) > 31:
308 if (int(vat[0:2]) + int(vat[2:4]) + int(vat[4:6]) + int(vat[6:8]) +
309 int(vat[8:10])) % 11 != 0:
311 if int(vat[0:10]) % 11 != 0:
315 def check_vat_de(self, vat):
317 Check Germany VAT number.
325 if int(vat[0:7]) <= 0:
329 sum = (2 * ((int(vat[i]) + sum + 9) % 10 + 1)) % 11
333 if int(vat[8]) != check:
337 def check_vat_dk(self, vat):
339 Check Denmark VAT number.
349 sum = 2 * int(vat[0]) + 7 * int(vat[1]) + 6 * int(vat[2]) + \
350 5 * int(vat[3]) + 4 * int(vat[4]) + 3 * int(vat[5]) + \
351 2 * int(vat[6]) + int(vat[7])
356 def check_vat_ee(self, vat):
358 Check Estonia VAT number.
366 sum = 3 * int(vat[0]) + 7 * int(vat[1]) + 1 * int(vat[2]) + \
367 3 * int(vat[3]) + 7 * int(vat[4]) + 1 * int(vat[5]) + \
368 3 * int(vat[6]) + 7 * int(vat[7])
369 check = 10 - (sum % 10)
372 if check != int(vat[8]):
376 def check_vat_es(self, vat):
378 Check Spain VAT number.
408 #Legal persons with profit aim
409 if vat[0] in ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'U', 'V'):
414 sum = mult_add(2, int(vat[1])) + int(vat[2]) + \
415 mult_add(2, int(vat[3])) + int(vat[4]) + \
416 mult_add(2, int(vat[5])) + int(vat[6]) + \
417 mult_add(2, int(vat[7]))
418 check = 10 - (sum % 10)
422 #Legal persons with non-profit aim
423 elif vat[0] in ('N', 'P', 'Q', 'R', 'S', 'W'):
428 sum = mult_add(2, int(vat[1])) + int(vat[2]) + \
429 mult_add(2, int(vat[3])) + int(vat[4]) + \
430 mult_add(2, int(vat[5])) + int(vat[6]) + \
431 mult_add(2, int(vat[7]))
432 check = 10 - (sum % 10)
433 check = chr(check + 64)
437 #Foreign natural persons, under age 14 or non-residents
438 elif vat[0] in ('K', 'L', 'M', 'X', 'Y', 'Z'):
440 check_value = '1' + vat[1:8]
442 check_value = '2' + vat[1:8]
444 check_value = vat[1:8]
450 check = 1 + (int(check_value) % 23)
456 #Spanish natural persons
462 check = 1 + (int(vat[:8]) % 23)
469 def check_vat_fi(self, vat):
471 Check Finland VAT number.
479 sum = 7 * int(vat[0]) + 9 * int(vat[1]) + 10 * int(vat[2]) + \
480 5 * int(vat[3]) + 8 * int(vat[4]) + 4 * int(vat[5]) + \
482 check = 11 - (sum % 11)
487 if check != int(vat[7]):
491 def check_vat_fr(self, vat):
493 Check France VAT number.
511 check = ((int(vat[2:11]) * 100) + 12) % 97
512 if check != int(vat[0:2]):
516 conv = ['0', '1', '2', '3', '4', '5', '6', '7',
517 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
518 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T',
519 'U', 'V', 'W', 'X', 'Y', 'Z']
520 if vat[0] not in conv \
521 or vat[1] not in conv:
523 c1 = conv.index(vat[0])
524 c2 = conv.index(vat[1])
527 sum = c1 * 24 + c2 - 10
529 sum = c1 * 34 + c2 - 100
532 sum = (int(sum) / 11) + 1
533 y = (int(vat[2:11]) + sum) % 11
538 def check_vat_gb(self, vat):
540 Check United Kingdom VAT number.
550 if int(vat[2:5]) >= 500:
554 if int(vat[2:5]) < 500:
558 elif len(vat) in (9, 10):
564 if int(vat[0:7]) < 1:
566 if int(vat[0:7]) > 19999 and int(vat[0:7]) < 1000000:
568 if int(vat[7:9]) > 97:
570 if len(vat) == 10 and int(vat[9]) != 3:
573 sum = 8 * int(vat[0]) + 7 * int(vat[1]) + 6 * int(vat[2]) + \
574 5 * int(vat[3]) + 4 * int(vat[4]) + 3 * int(vat[5]) + \
575 2 * int(vat[6]) + 10 * int(vat[7]) + int(vat[8])
576 if int(vat[0:3]) > 100:
577 if sum % 97 not in (0, 55, 42):
583 elif len(vat) in (12, 13):
589 if int(vat[0:3]) not in (0, 1):
592 if int(vat[3:10]) < 1:
594 if int(vat[3:10]) > 19999 and int(vat[3:10]) < 1000000:
596 if int(vat[10:12]) > 97:
598 if len(vat) == 13 and int(vat[12]) != 3:
601 sum = 8 * int(vat[3]) + 7 * int(vat[4]) + 6 * int(vat[5]) + \
602 5 * int(vat[6]) + 4 * int(vat[7]) + 3 * int(vat[8]) + \
603 2 * int(vat[9]) + 10 * int(vat[10]) + int(vat[11])
609 def check_vat_gr(self, vat):
611 Check Greece VAT number.
618 sum = 128 * int(vat[0]) + 64 * int(vat[1]) + 32 * int(vat[2]) + \
619 16 * int(vat[3]) + 8 * int(vat[4]) + 4 * int(vat[5]) + \
624 if check != int(vat[7]):
628 sum = 256 * int(vat[0]) + 128 * int(vat[1]) + 64 * int(vat[2]) + \
629 32 * int(vat[3]) + 16 * int(vat[4]) + 8 * int(vat[5]) + \
630 4 * int(vat[6]) + 2 * int(vat[7])
634 if check != int(vat[8]):
639 def check_vat_el(self, vat):
640 return self.check_vat_gr(vat)
642 def check_vat_hu(self, vat):
644 Check Hungary VAT number.
654 sum = 9 * int(vat[0]) + 7 * int(vat[1]) + 3 * int(vat[2]) + \
655 1 * int(vat[3]) + 9 * int(vat[4]) + 7 * int(vat[5]) + \
657 check = 10 - (sum % 10)
660 if check != int(vat[7]):
664 def check_vat_ie(self, vat):
666 Check Ireland VAT number.
670 if (ord(vat[1]) >= 65 and ord(vat[1]) <= 90) \
671 or vat[1] in ('+', '*'):
681 sum = 7 * int(vat[2]) + 6 * int(vat[3]) + 5 * int(vat[4]) + \
682 4 * int(vat[5]) + 3 * int(vat[6]) + 2 * int(vat[0])
687 check = chr(check + 64)
697 sum = 8 * int(vat[0]) + 7 * int(vat[1]) + 6 * int(vat[2]) + \
698 5 * int(vat[3]) + 4 * int(vat[4]) + 3 * int(vat[5]) + \
704 check = chr(check + 64)
709 def check_vat_it(self, vat):
711 Check Italy VAT number.
719 if int(vat[0:7]) <= 0:
721 if int(vat[7:10]) <= 0:
723 if int(vat[7:10]) > 100 and int(vat[7:10]) < 120:
726 sum = int(vat[0]) + mult_add(2, int(vat[1])) + int(vat[2]) + \
727 mult_add(2, int(vat[3])) + int(vat[4]) + \
728 mult_add(2, int(vat[5])) + int(vat[6]) + \
729 mult_add(2, int(vat[7])) + int(vat[8]) + \
730 mult_add(2, int(vat[9]))
731 check = 10 - (sum % 10)
734 if check != int(vat[10]):
738 def check_vat_lt(self, vat):
740 Check Lithuania VAT number.
750 sum = 1 * int(vat[0]) + 2 * int(vat[1]) + 3 * int(vat[2]) + \
751 4 * int(vat[3]) + 5 * int(vat[4]) + 6 * int(vat[5]) + \
752 7 * int(vat[6]) + 8 * int(vat[7])
754 sum = 3 * int(vat[0]) + 4 * int(vat[1]) + 5 * int(vat[2]) + \
755 6 * int(vat[3]) + 7 * int(vat[4]) + 8 * int(vat[5]) + \
756 9 * int(vat[6]) + 1 * int(vat[7])
760 if check != int(vat[8]):
764 if int(vat[10]) != 1:
766 sum = 1 * int(vat[0]) + 2 * int(vat[1]) + 3 * int(vat[2]) + \
767 4 * int(vat[3]) + 5 * int(vat[4]) + 6 * int(vat[5]) + \
768 7 * int(vat[6]) + 8 * int(vat[7]) + 9 * int(vat[8]) + \
769 1 * int(vat[9]) + 2 * int(vat[10])
771 sum = 3 * int(vat[0]) + 4 * int(vat[1]) + 5 * int(vat[2]) + \
772 6 * int(vat[3]) + 7 * int(vat[4]) + 8 * int(vat[5]) + \
773 9 * int(vat[6]) + 1 * int(vat[7]) + 2 * int(vat[8]) + \
774 3 * int(vat[9]) + 4 * int(vat[10])
778 if check != int(vat[11]):
783 def check_vat_lu(self, vat):
785 Check Luxembourg VAT number.
793 if int(vat[0:6]) <= 0:
795 check = int(vat[0:6]) % 89
796 if check != int(vat[6:8]):
800 def check_vat_lv(self, vat):
802 Check Latvia VAT number.
811 sum = 9 * int(vat[0]) + 1 * int(vat[1]) + 4 * int(vat[2]) + \
812 8 * int(vat[3]) + 3 * int(vat[4]) + 10 * int(vat[5]) + \
813 2 * int(vat[6]) + 5 * int(vat[7]) + 7 * int(vat[8]) + \
815 if sum % 11 == 4 and int(vat[0]) == 9:
818 check = 4 - (sum % 11)
820 check = 14 - (sum % 11)
822 check = 3 - (sum % 11)
823 if check != int(vat[10]):
827 if int(vat[2:4]) == 2 and int(vat[4:6]) % 4 > 0:
828 if int(vat[0:2]) < 1 or int(vat[0:2]) > 28:
830 if int(vat[2:4]) == 2 and int(vat[4:6]) % 4 == 0:
831 if int(vat[0:2]) < 1 or int(vat[0:2]) > 29:
833 if int(vat[2:4]) in (4, 6, 9, 11):
834 if int(vat[0:2]) < 1 or int(vat[0:2]) > 30:
836 if int(vat[2:4]) in (1, 3, 5, 7, 8, 10, 12):
837 if int(vat[0:2]) < 1 or int(vat[0:2]) > 31:
839 if int(vat[2:4]) < 1 or int(vat[2:4]) > 12:
843 def check_vat_mt(self, vat):
845 Check Malta VAT number.
854 if int(vat[0:6]) < 100000:
857 sum = 3 * int(vat[0]) + 4 * int(vat[1]) + 6 * int(vat[2]) + \
858 7 * int(vat[3]) + 8 * int(vat[4]) + 9 * int(vat[5])
859 check = 37 - (sum % 37)
860 if check != int(vat[6:8]):
864 def check_vat_nl(self, vat):
866 Check Netherlands VAT number.
875 if int(vat[0:8]) <= 0:
880 sum = 9 * int(vat[0]) + 8 * int(vat[1]) + 7 * int(vat[2]) + \
881 6 * int(vat[3]) + 5 * int(vat[4]) + 4 * int(vat[5]) + \
882 3 * int(vat[6]) + 2 * int(vat[7])
887 if check != int(vat[8]):
891 def check_vat_pl(self, vat):
893 Check Poland VAT number.
902 sum = 6 * int(vat[0]) + 5 * int(vat[1]) + 7 * int(vat[2]) + \
903 2 * int(vat[3]) + 3 * int(vat[4]) + 4 * int(vat[5]) + \
904 5 * int(vat[6]) + 6 * int(vat[7]) + 7 * int(vat[8])
908 if check != int(vat[9]):
912 def check_vat_pt(self, vat):
914 Check Portugal VAT number.
926 sum = 9 * int(vat[0]) + 8 * int(vat[1]) + 7 * int(vat[2]) + \
927 6 * int(vat[3]) + 5 * int(vat[4]) + 4 * int(vat[5]) + \
928 3 * int(vat[6]) + 2 * int(vat[7])
929 check = 11 - (sum % 11)
930 if check == 10 or check == 11:
934 def check_vat_ro(self, vat):
936 Check Romania VAT number.
943 if len(vat) >= 2 and len(vat) <= 10:
944 vat = (10 - len(vat)) * '0' + vat
945 sum = 7 * int(vat[0]) + 5 * int(vat[1]) + 3 * int(vat[2]) + \
946 2 * int(vat[3]) + 1 * int(vat[4]) + 7 * int(vat[5]) + \
947 5 * int(vat[6]) + 3 * int(vat[7]) + 2 * int(vat[8])
948 check = (sum * 10) % 11
951 if check != int(vat[9]):
955 if int(vat[0]) not in (1, 2, 3, 4, 6):
957 if int(vat[3:5]) < 1 or int(vat[3:5]) > 12:
959 if int(vat[3:5]) == 2 and int(vat[1:3]) % 4 > 0:
960 if int(vat[5:7]) < 1 or int(vat[5:7]) > 28:
962 if int(vat[3:5]) == 2 and int(vat[1:3]) % 4 == 0:
963 if int(vat[5:7]) < 1 or int(vat[5:7]) > 29:
965 if int(vat[3:5]) in (4, 6, 9, 11):
966 if int(vat[5:7]) < 1 or int(vat[5:7]) > 30:
968 if int(vat[3:5]) in (1, 3, 5, 7, 8, 10, 12):
969 if int(vat[5:7]) < 1 or int(vat[5:7]) > 31:
972 sum = 2 * int(vat[0]) + 7 * int(vat[1]) + 9 * int(vat[2]) + \
973 1 * int(vat[3]) + 4 * int(vat[4]) + 6 * int(vat[5]) + \
974 3 * int(vat[6]) + 5 * int(vat[7]) + 8 * int(vat[8]) + \
975 2 * int(vat[9]) + 7 * int(vat[10]) + 9 * int(vat[11])
979 if check != int(vat[12]):
984 def check_vat_se(self, vat):
986 Check Sweden VAT number.
995 if int(vat[9:11]) < 0:
998 sum = mult_add(2, int(vat[0])) + int(vat[1]) + \
999 mult_add(2, int(vat[2])) + int(vat[3]) + \
1000 mult_add(2, int(vat[4])) + int(vat[5]) + \
1001 mult_add(2, int(vat[6])) + int(vat[7]) + \
1002 mult_add(2, int(vat[8]))
1003 check = 10 - (sum % 10)
1006 if check != int(vat[9]):
1010 def check_vat_si(self, vat):
1012 Check Slovenia VAT number.
1020 if int(vat[0:7]) <= 999999:
1023 sum = 8 * int(vat[0]) + 7 * int(vat[1]) + 6 * int(vat[2]) + \
1024 5 * int(vat[3]) + 4 * int(vat[4]) + 3 * int(vat[5]) + \
1026 check = 11 - (sum % 11)
1031 if check != int(vat[7]):
1035 def check_vat_sk(self, vat):
1037 Check Slovakia VAT number.
1043 if len(vat) not in(9, 10):
1046 if int(vat[0:2]) in (0, 10, 20) and len(vat) == 10:
1050 if int(vat[0:2]) < 54 or int(vat[0:2]) > 99:
1054 if int(vat[0:2]) > 53 :
1057 if int(vat[2:4]) < 1:
1059 if int(vat[2:4]) > 12 and int(vat[2:4]) < 51:
1061 if int(vat[2:4]) > 62:
1063 if int(vat[2:4]) in (2, 52) and int(vat[0:2]) % 4 > 0:
1064 if int(vat[4:6]) < 1 or int(vat[4:6]) > 28:
1066 if int(vat[2:4]) in (2, 52) and int(vat[0:2]) % 4 == 0:
1067 if int(vat[4:6]) < 1 or int(vat[4:6]) > 29:
1069 if int(vat[2:4]) in (4, 6, 9, 11, 54, 56, 59, 61):
1070 if int(vat[4:6]) < 1 or int(vat[4:6]) > 30:
1072 if int(vat[2:4]) in (1, 3, 5, 7, 8, 10, 12,
1073 51, 53, 55, 57, 58, 60, 62):
1074 if int(vat[4:6]) < 1 or int(vat[4:6]) > 31:
1078 __check_vat_mx_re = re.compile(r"(?P<primeras>[A-Za-z\xd1\xf1&]{3,4})" \
1080 r"(?P<ano>[0-9]{2})(?P<mes>[01][0-9])(?P<dia>[0-3][0-9])" \
1082 r"(?P<code>[A-Za-z0-9&\xd1\xf1]{3})$")
1084 def check_vat_mx(self, vat):
1085 ''' Mexican VAT verification
1087 Verificar RFC México
1089 # we convert to 8-bit encoding, to help the regex parse only bytes
1090 vat = ustr(vat).encode('iso8859-1')
1091 m = self.__check_vat_mx_re.match(vat)
1096 ano = int(m.group('ano'))
1101 datetime.date(ano, int(m.group('mes')), int(m.group('dia')))
1105 #Valid format and valid date
1108 def check_vat_hr(self, vat):
1110 Check Croatia VAT number.
1124 t = (2 * ((t + c) % 10 or 10)) % 11
1125 check = (11 - t) % 10
1126 if check != int(vat[10]):
1131 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: