[IMP] account: add generic base_vat methods to enable vat validation without the dependency

To enable VAT validation (VIES/ simple), the base_vat module needs to be installed.
base_vat extends models where the validation should apply. This means it only works with models in account, unless the module is added as a dependency (base_vat depends on account)
To avoid this dependency (in account reports - see enterprise PR odoo/enterprise#34068), two methods required for VAT validation are added to res.partner so that the enterprise module is able to use this feature with/without base_vat.

closes odoo/odoo#106046

Signed-off-by: Olivier Colson (oco) <oco@odoo.com>
This commit is contained in:
Habib (ayh)
2023-04-25 14:06:57 +02:00
parent bacd02f91a
commit 39c78c92ff
2 changed files with 31 additions and 15 deletions
+29
View File
@@ -667,6 +667,35 @@ class ResPartner(models.Model):
raise e
_logger.debug('Another transaction already locked partner rows. Cannot update partner ranks.')
@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()
@api.model
def _build_vat_error_message(self, country_code, wrong_vat, record_label):
""" Prepare an error message for the VAT number that failed validation
:param country_code: string of lowercase country code
:param wrong_vat: the vat number that was validated
:param record_label: a string to desribe the record that failed a VAT validation check
:return: The error message string
"""
return ""
@api.model
def get_partner_localisation_fields_required_to_invoice(self, country_id):
""" Returns the list of fields that needs to be filled when creating an invoice for the selected country.
+2 -15
View File
@@ -192,21 +192,7 @@ class ResPartner(models.Model):
@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.
A first check is made by using the first two characters of the VAT as
the country code. If 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.
.. 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.
"""
# OVERRIDE account
check_result = None
# First check with country code as prefix of the TIN
@@ -256,6 +242,7 @@ class ResPartner(models.Model):
@api.model
def _build_vat_error_message(self, country_code, wrong_vat, record_label):
# OVERRIDE account
if self.env.context.get('company_id'):
company = self.env['res.company'].browse(self.env.context['company_id'])
else: