X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=addons%2Fbase_vat%2Fbase_vat.py;h=6393c0a61829d9dca55009338cf1d541cfc86590;hb=00c300a07b935bd69639e12045d8165751236cd7;hp=190541bbcfb6ef22a4d7bbf8ab9146c8f29b6ec4;hpb=3432fe6d651b569db5dc0c4c88586942fac1ae2e;p=odoo%2Fodoo.git diff --git a/addons/base_vat/base_vat.py b/addons/base_vat/base_vat.py index 190541b..6393c0a 100644 --- a/addons/base_vat/base_vat.py +++ b/addons/base_vat/base_vat.py @@ -23,6 +23,7 @@ import string from osv import osv, fields from tools.translate import _ +from tools.misc import ustr import re import datetime @@ -61,11 +62,17 @@ class res_partner(osv.osv): Check the VAT number depending of the country. http://sima-pc.com/nif.php ''' + country_obj = self.pool.get('res.country') for partner in self.browse(cr, uid, ids, context=context): if not partner.vat: continue vat_country, vat_number = self._split_vat(partner.vat) if not hasattr(self, 'check_vat_' + vat_country): + #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 + #and we simply didn't have implemented that function. In that case we continue. + if country_obj.search(cr, uid, [('code', 'ilike', vat_country)], context=context): + continue + #Otherwise, it means that the country code isn't valid and we return False. return False check = getattr(self, 'check_vat_' + vat_country) if not check(vat_number): @@ -1068,23 +1075,30 @@ class res_partner(osv.osv): return False return True - __check_vat_mx_re = re.compile(r"(?P[A-Z&ñÑ]{3,4})" \ + __check_vat_mx_re = re.compile(r"(?P[A-Za-z\xd1\xf1&]{3,4})" \ r"[ \-_]?" \ - r"(?P[0-9]{2})(?P[01][1-9])(?P[0-3][0-9])" \ + r"(?P[0-9]{2})(?P[01][0-9])(?P[0-3][0-9])" \ r"[ \-_]?" \ - r"(?P[A-Z0-9&ñÑ\xd1\xf1]{3})$") + r"(?P[A-Za-z0-9&\xd1\xf1]{3})$") - def check_vat_mx(vat): + def check_vat_mx(self, vat): ''' Mexican VAT verification Verificar RFC México ''' + # we convert to 8-bit encoding, to help the regex parse only bytes + vat = ustr(vat).encode('iso8859-1') m = self.__check_vat_mx_re.match(vat) if not m: #No valid format return False try: - datetime.date(int(m.group('ano')), int(m.group('mes')), int(m.group('dia'))) + ano = int(m.group('ano')) + if ano > 30: + ano = 1900 + ano + else: + ano = 2000 + ano + datetime.date(ano, int(m.group('mes')), int(m.group('dia'))) except ValueError: return False