f***@gmail.com
2016-07-11 14:43:38 UTC
Por si le interesa a alguien, hice una modificación al módulo party para
incluir el RFC mexicano (equivalente al número VAT mexicano). Esto es para
la version 4.0 de tryton (tryton-modules-party_4.0.1-1~8jessie+1_all.deb)
*** /tmp/ediff27895fd 2016-07-11 09:17:23.966602026 -0500
--- /usr/lib/python2.7/dist-packages/trytond/modules/party/party.py
2016-07-09 21:15:31.914255012 -0500
***************
*** 3,8 ****
--- 3,9 ----
from itertools import groupby
import stdnum.eu.vat as vat
+ import stdnum.mx.rfc as rfc
import stdnum.exceptions
from sql import Null
from sql.functions import CharLength
***************
*** 126,132 ****
@classmethod
def _vat_types(cls):
! return ['eu_vat']
def get_vat_code(self, name):
types = self._vat_types()
--- 127,133 ----
@classmethod
def _vat_types(cls):
! return ['eu_vat', 'mx_rfc']
def get_vat_code(self, name):
types = self._vat_types()
***************
*** 266,271 ****
--- 267,274 ----
type = None
if vat.is_valid(code):
type = 'eu_vat'
+ if rfc.is_valid(code):
+ type = 'mx_rfc'
identifiers.append(
cls(party=party_id, code=code, type=type))
cls.save(identifiers)
***************
*** 276,281 ****
--- 279,285 ----
def get_types(cls):
return [
(None, ''),
+ ('mx_rfc', 'RFC'),
('eu_vat', 'VAT'),
]
***************
*** 286,301 ****
return vat.compact(self.code)
except stdnum.exceptions.ValidationError:
pass
return self.code
def pre_validate(self):
super(PartyIdentifier, self).pre_validate()
self.check_code()
def check_code(self):
if self.type == 'eu_vat':
if not vat.is_valid(self.code):
! if self.party.id > 0:
party = self.party.rec_name
else:
party = ''
--- 290,323 ----
return vat.compact(self.code)
except stdnum.exceptions.ValidationError:
pass
+
+ if self.type == 'mx_rfc':
+ try:
+ return rfc.compact(self.code)
+ except stdnum.exceptions.ValidationError:
+ pass
return self.code
def pre_validate(self):
super(PartyIdentifier, self).pre_validate()
self.check_code()
+ @fields.depends('type', 'party', 'code')
def check_code(self):
if self.type == 'eu_vat':
if not vat.is_valid(self.code):
! if self.party and self.party.id > 0:
! party = self.party.rec_name
! else:
! party = ''
! self.raise_user_error('invalid_vat', {
! 'code': self.code,
! 'party': party,
! })
!
! if self.type == 'mx_rfc':
! if not rfc.is_valid(self.code):
! if self.party and self.party.id > 0:
party = self.party.rec_name
else:
party = ''
***************
*** 345,350 ****
--- 367,379 ----
parties = Party.browse(Transaction().context.get('active_ids'))
for party in parties:
for identifier in party.identifiers:
+ if identifier.type == 'mx_rfc':
+ if not rfc.is_valid(identifier.code):
+ parties_failed.append(party.id)
+ else:
+ parties_succeed.append(party.id)
+ continue
+
if identifier.type != 'eu_vat':
continue
try:
incluir el RFC mexicano (equivalente al número VAT mexicano). Esto es para
la version 4.0 de tryton (tryton-modules-party_4.0.1-1~8jessie+1_all.deb)
*** /tmp/ediff27895fd 2016-07-11 09:17:23.966602026 -0500
--- /usr/lib/python2.7/dist-packages/trytond/modules/party/party.py
2016-07-09 21:15:31.914255012 -0500
***************
*** 3,8 ****
--- 3,9 ----
from itertools import groupby
import stdnum.eu.vat as vat
+ import stdnum.mx.rfc as rfc
import stdnum.exceptions
from sql import Null
from sql.functions import CharLength
***************
*** 126,132 ****
@classmethod
def _vat_types(cls):
! return ['eu_vat']
def get_vat_code(self, name):
types = self._vat_types()
--- 127,133 ----
@classmethod
def _vat_types(cls):
! return ['eu_vat', 'mx_rfc']
def get_vat_code(self, name):
types = self._vat_types()
***************
*** 266,271 ****
--- 267,274 ----
type = None
if vat.is_valid(code):
type = 'eu_vat'
+ if rfc.is_valid(code):
+ type = 'mx_rfc'
identifiers.append(
cls(party=party_id, code=code, type=type))
cls.save(identifiers)
***************
*** 276,281 ****
--- 279,285 ----
def get_types(cls):
return [
(None, ''),
+ ('mx_rfc', 'RFC'),
('eu_vat', 'VAT'),
]
***************
*** 286,301 ****
return vat.compact(self.code)
except stdnum.exceptions.ValidationError:
pass
return self.code
def pre_validate(self):
super(PartyIdentifier, self).pre_validate()
self.check_code()
def check_code(self):
if self.type == 'eu_vat':
if not vat.is_valid(self.code):
! if self.party.id > 0:
party = self.party.rec_name
else:
party = ''
--- 290,323 ----
return vat.compact(self.code)
except stdnum.exceptions.ValidationError:
pass
+
+ if self.type == 'mx_rfc':
+ try:
+ return rfc.compact(self.code)
+ except stdnum.exceptions.ValidationError:
+ pass
return self.code
def pre_validate(self):
super(PartyIdentifier, self).pre_validate()
self.check_code()
+ @fields.depends('type', 'party', 'code')
def check_code(self):
if self.type == 'eu_vat':
if not vat.is_valid(self.code):
! if self.party and self.party.id > 0:
! party = self.party.rec_name
! else:
! party = ''
! self.raise_user_error('invalid_vat', {
! 'code': self.code,
! 'party': party,
! })
!
! if self.type == 'mx_rfc':
! if not rfc.is_valid(self.code):
! if self.party and self.party.id > 0:
party = self.party.rec_name
else:
party = ''
***************
*** 345,350 ****
--- 367,379 ----
parties = Party.browse(Transaction().context.get('active_ids'))
for party in parties:
for identifier in party.identifiers:
+ if identifier.type == 'mx_rfc':
+ if not rfc.is_valid(identifier.code):
+ parties_failed.append(party.id)
+ else:
+ parties_succeed.append(party.id)
+ continue
+
if identifier.type != 'eu_vat':
continue
try: