4
#############################################################################
5
# Module Writen to OpenERP, Open Source Management Solution
6
# CopyLeft 2012 - http://www.grupoaltegra.com
7
# You are free to share, copy, distribute, transmit, adapt and use for commercial purpose
8
# More information about license: http://www.gnu.org/licenses/agpl.html
9
# info Grupo Altegra (openerp@grupoaltegra.com)
11
#############################################################################
13
# Coded by: Carlos Blanco (carlos.blanco@grupoaltegra.com)
15
#############################################################################
17
# This program is free software: you can redistribute it and/or modify
18
# it under the terms of the GNU Affero General Public License as
19
# published by the Free Software Foundation, either version 3 of the
20
# License, or (at your option) any later version.
22
# This program is distributed in the hope that it will be useful,
23
# but WITHOUT ANY WARRANTY; without even the implied warranty of
24
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
# GNU Affero General Public License for more details.
27
# You should have received a copy of the GNU Affero General Public License
28
# along with this program. If not, see <http://www.gnu.org/licenses/>.
30
#############################################################################
33
from openerp.osv import fields, osv
34
from openerp.tools.translate import _
41
'ch': 'CHE-123.456.788 TVA or CH TVA 123456', #Swiss by Yannick Vaucher @ Camptocamp
50
'fr': 'FR32123456789',
54
'hr': 'HR01234567896', # Croatia, contributed by Milan Tribuson
56
'it': 'IT12345670017',
59
'lv': 'LV41234567891',
61
'mx': 'MXABC123456T1B',
62
'nl': 'NL123456782B90',
67
'se': 'SE123456789701',
72
class res_partner(osv.Model):
73
_inherit = 'res.partner'
75
def check_vat(self, cr, uid, ids, context=None):
77
#~ return all( [ self.check_vat_mx( partner.vat ) for partner in self.browse(cr, uid, ids, context=context) ] )
78
# Se Verifica si tiene el codigo de pais agregado en el RFC
79
for partner in self.browse(cr, uid, ids, context=context):
82
country_code = partner.vat[:2]
83
# Si tiene el codigo de pais se quita y solo se toma n cuenta el RFC
84
if country_code.count('MX'):
86
# Si no si manda todo el RFC sin quitarne nada para validarlo
89
vat_list.append(self.check_vat_mx( vat ))
94
def _construct_constraint_msg(self, cr, uid, ids, context=None):
95
# Se construye el mensaje que se mandara si el RFC es incorrecto
96
def default_vat_check(cn, vn):
97
# by default, a VAT number is valid if:
98
# it starts with 2 letters
99
# has more than 3 characters
100
return cn[0] in string.ascii_lowercase and cn[1] in string.ascii_lowercase
101
vat_country, vat_number = self._split_vat(self.browse(cr, uid, ids)[0].vat)
102
vat_no = "'CC##' (CC=Country Code, ##=VAT Number)"
103
if default_vat_check(vat_country, vat_number):
104
vat_no = _ref_vat[vat_country] if vat_country in _ref_vat else vat_no
105
return '\n' + _('This VAT number does not seem to be valid.\nNote: the expected format is %s') % vat_no
107
_constraints = [(check_vat, _construct_constraint_msg, ["vat"])]
109
def write(self, cr, uid, ids, vals, context=None):
111
Se redefine el metodo write para ponerle el codigo de pais al principio del RFC
117
vals['vat'] = vals['vat'] and vals['vat'].replace(u'-', u'').replace(u' ', u'').replace(u'.', u'').replace(u'/', u'').replace(u'ñ', u'Ñ').upper() or vals['vat']
118
country_code = vals['vat'][:2]
119
if not country_code.count('MX'):
120
vals['vat'] = 'MX'+vals['vat']
121
return super(res_partner, self).write(cr, uid, ids, vals, context=context)