From 8fa1e671bc6870bc3071fbd7a449dd3ac15b2377 Mon Sep 17 00:00:00 2001 From: Katherine Zaoral Date: Wed, 3 Mar 2021 18:50:55 +0000 Subject: [PATCH] [FIX] l10n_latam_base: identification type default Identification type was always been overwrite by the _onchange_country even when just opening the contact form, this was always setting the is_vat identification type as default without taking into account if the user has defined their own default.: * If Identification type is set and it is compatible with the country then we leave it as it is (this is the case the identification type has been set by a default). * If Identification type is set but is not compatible with the country then compute and set the Identification type that is is_vat True for the country Where country is the one set in the partner record, if not set will use the country of the move's company, if not defined then will use the country of the environment company closes odoo/odoo#67628 X-original-commit: 8e9b1c404a71c0a7dce37c7f5f6ecef1396e0a1a Signed-off-by: Josse Colpaert --- addons/l10n_latam_base/models/res_partner.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/l10n_latam_base/models/res_partner.py b/addons/l10n_latam_base/models/res_partner.py index d4d5769f07b..10396dbbf17 100644 --- a/addons/l10n_latam_base/models/res_partner.py +++ b/addons/l10n_latam_base/models/res_partner.py @@ -24,5 +24,8 @@ class ResPartner(models.Model): @api.onchange('country_id') def _onchange_country(self): country = self.country_id or self.company_id.country_id or self.env.company.country_id - self.l10n_latam_identification_type_id = self.env['l10n_latam.identification.type'].search( - [('country_id', '=', country.id), ('is_vat', '=', True)], limit=1) or self.env.ref('l10n_latam_base.it_vat', raise_if_not_found=False) + identification_type = self.l10n_latam_identification_type_id + if not identification_type or (identification_type.country_id != country): + self.l10n_latam_identification_type_id = self.env['l10n_latam.identification.type'].search( + [('country_id', '=', country.id), ('is_vat', '=', True)], limit=1) or self.env.ref( + 'l10n_latam_base.it_vat', raise_if_not_found=False)