1
# -*- encoding: utf-8 -*-
2
###########################################################################
3
# Module Writen to OpenERP, Open Source Management Solution
5
# Copyright (c) 2010 moylop260 - http://moylop.blogspot.com/
7
# info moylop260 (moylop260@hotmail.com)
8
############################################################################
9
# Coded by: moylop260 (moylop260@hotmail.com)
10
############################################################################
12
# This program is free software: you can redistribute it and/or modify
13
# it under the terms of the GNU Affero General Public License as
14
# published by the Free Software Foundation, either version 3 of the
15
# License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU Affero General Public License for more details.
22
# You should have received a copy of the GNU Affero General Public License
23
# along with this program. If not, see <http://www.gnu.org/licenses/>.
25
##############################################################################
27
from osv import fields
28
from tools.translate import _
31
"""Convierte vocales accentuadas, ñ y ç a sus caracteres equivalentes ASCII"""
32
old_chars = ['á', 'é', 'í', 'ó', 'ú', 'à', 'è', 'ì', 'ò', 'ù', 'ä', 'ë', 'ï', 'ö', 'ü', 'â', 'ê', 'î', \
33
'ô', 'û', 'Á', 'É', 'Í', 'Ú', 'Ó', 'À', 'È', 'Ì', 'Ò', 'Ù', 'Ä', 'Ë', 'Ï', 'Ö', 'Ü', 'Â', 'Ê', 'Î', \
34
'Ô', 'Û', 'ñ', 'Ñ', 'ç', 'Ç', 'ª', 'º', '°', ' '
36
new_chars = ['a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', \
37
'o', 'u', 'A', 'E', 'I', 'O', 'U', 'A', 'E', 'I', 'O', 'U', 'A', 'E', 'I', 'O', 'U', 'A', 'E', 'I', \
38
'O', 'U', 'n', 'N', 'c', 'C', 'a', 'o', 'o', ' '
40
for old, new in zip(old_chars, new_chars):
42
text = text.replace(unicode(old,'UTF-8'), new)
45
text = text.replace(old, new)
47
raise osv.except_osv(_('Warning !'), 'No se pudo re-codificar la cadena [%s] en la letra [%s]'%(text, old) )
50
class res_partner(osv.osv):
51
_inherit = 'res.partner'
53
def check_vat(self, cr, uid, ids, context=None):
57
#[IMP] base_vat: check_vat_mx by moylop260@hotmail.com, tested with 242,665 real RFC's
60
map_initials = "[A-Z|&]"*4
61
map_date = "[0-9][0-9][0-1][1-9][0-3][0-9]"
62
map_code = "[A-Z|&|0-9]"*3
63
mapping = map_initials + map_date + map_code
64
for partner in self.browse(cr, uid, ids, context=context):
68
vat = conv_ascii(vat).upper().replace(' ', '').replace('-', '')
69
#vat = vat.upper().replace('ñ', 'Ñ').replace('\xd1', 'Ñ').replace('\xf1', 'Ñ')#upper ascii
70
#vat = vat.replace('Ñ', 'X')#Replace ascii valid char, these is problems with match in regexp
71
#vat = vat.replace(' ', '').replace('-', '')#Replace some char valid, but no required
73
vat = "X" + vat#Add a valid char, for pass validation with case with cad of len = 12
76
regex = re.compile(mapping)
77
if not regex.match(vat):
80
date_match = re.search(map_date, vat)
81
date_format = '%y%m%d'
83
time.strptime(date_match.group(), date_format)
85
#Valid format, but date wrong
87
#Valid format and valid date
90
def _______ANTERIOR____check_vat(self, cr, uid, ids, context=None):
91
for partner in self.browse(cr, uid, ids, context=context):
96
vat = ''.join( [x for x in vat if x.isupper() or x.isdigit() ] ) #Remove all characteres what no is digit or letter
98
vat = "X" + vat#Add a valid char, for pass validation with case with cad of len = 12
99
if len(vat) <> 13 or not( vat[:4].isupper()
100
and vat[4:10].isdigit() and vat[10:13].isalnum() ):
104
_constraints = [(check_vat, _('Error RFC es incorrecto, debería ser algo como XYZA010203A01 or XYZ0102039A8'), ["vat"])]
b'\\ No newline at end of file'