From 04d8c7d2d2f21c136b4208d23a1f21809a60f6e3 Mon Sep 17 00:00:00 2001 From: Julien Van Roy <juvr@odoo.com> Date: Wed, 20 Sep 2023 10:02:23 +0200 Subject: [PATCH] [FIX] account: add _run_vat_test in account to avoid base_vat dependency This way, it can be used without having to add the dependency to `base_vat`. For instance, in `account_edi_ubl_cii` in `_import_retrieve_and_fill_partner`. This commit essentially backports part of commit 212be2920affdab5baf14b3025ef31ee2d6a652b closes odoo/odoo#135977 Signed-off-by: Laurent Smet (las) <las@odoo.com> --- addons/account/models/partner.py | 15 +++++++++++++++ .../models/account_edi_xml_cii_facturx.py | 3 ++- addons/base_vat/models/res_partner.py | 15 +-------------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index 70f68c418868..2b1c2964a8d7 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -584,6 +584,21 @@ class ResPartner(models.Model): else: raise e + @api.model + def _run_vat_test(self, vat_number, default_country, partner_is_company=True): + """ Checks a VAT number syntactically to ensure its validity upon saving. + :param vat_number: a string with the VAT number to check. + :param default_country: a res.country object + :param partner_is_company: True if the partner is a company, else False. + .. deprecated:: 16.0 + Will be removed in 16.2 + :return: The country code (in lower case) of the country the VAT number + was validated for, if it was validated. False if it could not be validated + against the provided or guessed country. None if no country was available + for the check, and no conclusion could be made with certainty. + """ + return default_country.code.lower() + def _merge_method(self, destination, source): """ Prevent merging partners that are linked to already hashed journal items. diff --git a/addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py b/addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py index 54ccc719e79d..7b5afbcfa944 100644 --- a/addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py +++ b/addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py @@ -261,7 +261,8 @@ class AccountEdiXmlCII(models.AbstractModel): mail = _find_value(f"//ram:{role}//ram:URIID[@schemeID='SMTP']") vat = _find_value(f"//ram:{role}/ram:SpecifiedTaxRegistration/ram:ID") phone = _find_value(f"//ram:{role}/ram:DefinedTradeContact/ram:TelephoneUniversalCommunication/ram:CompleteNumber") - self._import_retrieve_and_fill_partner(invoice_form, name=name, phone=phone, mail=mail, vat=vat) + country_code = _find_value(f'//ram:{role}/ram:PostalTradeAddress//ram:CountryID') + self._import_retrieve_and_fill_partner(invoice_form, name=name, phone=phone, mail=mail, vat=vat, country_code=country_code) # ==== currency_id ==== diff --git a/addons/base_vat/models/res_partner.py b/addons/base_vat/models/res_partner.py index cfc6299c1129..4140e9273bdb 100644 --- a/addons/base_vat/models/res_partner.py +++ b/addons/base_vat/models/res_partner.py @@ -166,20 +166,7 @@ class ResPartner(models.Model): @api.model def _run_vat_test(self, vat_number, default_country, partner_is_company=True): - """ Checks a VAT number, either syntactically or using VIES, depending - on the active company's configuration. - A first check is made by using the first two characters of the VAT as - the country code. It it fails, a second one is made using default_country instead. - - :param vat_number: a string with the VAT number to check. - :param default_country: a res.country object - :param partner_is_company: True if the partner is a company, else False - - :return: The country code (in lower case) of the country the VAT number - was validated for, if it was validated. False if it could not be validated - against the provided or guessed country. None if no country was available - for the check, and no conclusion could be made with certainty. - """ + # OVERRIDE account # Get company if self.env.context.get('company_id'): company = self.env['res.company'].browse(self.env.context['company_id']) -- GitLab