[REF] l10n_ec: Refactor _l10n_ec_get_identification_type
_l10n_ec_get_identification_type will get called quite often in a loop in the ATS report, so it's important that it gets orm-cached. This reimplementation removes calls to ref() and replaces them with calls to _xmlid_to_res_model_res_id() which is entirely orm-cached. closes odoo/odoo#147723 X-original-commit: f95540bb8b92e795b1331910049d0d6de7da120c Signed-off-by: Josse Colpaert <jco@odoo.com> Signed-off-by: Antoine Dupuis (andu) <andu@odoo.com>
This commit is contained in:
@@ -101,15 +101,24 @@ class ResPartner(models.Model):
|
||||
"""
|
||||
self.ensure_one()
|
||||
|
||||
def id_type_in(*args):
|
||||
return any([self.l10n_latam_identification_type_id == self.env.ref(arg) for arg in args])
|
||||
id_types_by_xmlid = {
|
||||
'l10n_ec.ec_dni': 'cedula', # DNI
|
||||
'l10n_ec.ec_ruc': 'ruc', # RUC
|
||||
'l10n_ec.ec_passport': 'ec_passport', # EC passport
|
||||
'l10n_latam_base.it_pass': 'passport', # Passport
|
||||
'l10n_latam_base.it_fid': 'foreign', # Foreign ID
|
||||
'l10n_latam_base.it_vat': 'foreign',
|
||||
}
|
||||
|
||||
if id_type_in('l10n_ec.ec_dni'):
|
||||
return 'cedula' # DNI
|
||||
elif id_type_in('l10n_ec.ec_ruc'):
|
||||
return 'ruc' # RUC
|
||||
elif id_type_in('l10n_latam_base.it_pass'):
|
||||
return 'passport' # Pasaporte
|
||||
elif id_type_in('l10n_latam_base.it_fid', 'l10n_latam_base.it_vat') \
|
||||
or self.l10n_latam_identification_type_id.country_id != self.env.ref('base.ec'):
|
||||
return 'foreign' # Identificacion del exterior
|
||||
# This method is orm-cached, which makes it more efficient in loops than get_external_id()
|
||||
xmlid_by_res_id = {
|
||||
self.env['ir.model.data']._xmlid_to_res_model_res_id(xmlid, raise_if_not_found=True)[1]: xmlid
|
||||
for xmlid in id_types_by_xmlid
|
||||
}
|
||||
|
||||
id_type_xmlid = xmlid_by_res_id.get(self.l10n_latam_identification_type_id.id)
|
||||
if id_type_xmlid in id_types_by_xmlid:
|
||||
return id_types_by_xmlid[id_type_xmlid]
|
||||
|
||||
if self.l10n_latam_identification_type_id.country_id.code != 'EC':
|
||||
return 'foreign'
|
||||
|
||||
Reference in New Issue
Block a user