summaryrefslogtreecommitdiff
path: root/addons/base_vat/models
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2020-01-29 08:10:31 +0000
committerNicolas Martinelli <nim@odoo.com>2020-01-30 12:34:24 +0000
commitba3062e6fc7968b138b67068cd02bdc7562e31dc (patch)
tree114a87986d9957ca31caaf3e4350f771aecbe072 /addons/base_vat/models
parent7efff597e50ead8d797eb9065c5862046b23435a (diff)
[FIX] base_vat: cache VIES result
- Activate the VIES online check - Create a partner of type Company and add several contacts - Set the VAT number, save A call to VIES is done for each contact. The field VAT is propagated from the parent company to the children, triggering the check on all partners. This is not problematic for local checks since those are fast. However, online checks take time which can lead to a timeout of the request if there are many contacts. Since the check is triggered through a constraint (`check_vat`), only one record at a time is checked. Therefore, it is not possible to build a local list of the VAT numbers to avoid duplicated verifications inside a single transaction. The solution is to store the result in cache. Since the call to the external API may fail (e.g. timeout), we extract the check to store only the successful calls. Closes #43939 opw-2181744 closes odoo/odoo#44298 X-original-commit: 0c7a3e95df41d4e12c2c5913c2f39e46f96fe77c Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Diffstat (limited to 'addons/base_vat/models')
-rw-r--r--addons/base_vat/models/res_partner.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/addons/base_vat/models/res_partner.py b/addons/base_vat/models/res_partner.py
index 77f0c50b575..a6604db44fc 100644
--- a/addons/base_vat/models/res_partner.py
+++ b/addons/base_vat/models/res_partner.py
@@ -21,7 +21,7 @@ try:
except ImportError:
stdnum = None
-from odoo import api, models, _
+from odoo import api, models, tools, _
from odoo.tools.misc import ustr
from odoo.exceptions import ValidationError
from stdnum.at.uid import compact as compact_at
@@ -134,11 +134,18 @@ class ResPartner(models.Model):
return check_func(vat_number)
@api.model
+ @tools.ormcache('vat')
+ def _check_vies(self, vat):
+ # Store the VIES result in the cache. In case an exception is raised during the request
+ # (e.g. service unavailable), the fallback on simple_vat_check is not kept in cache.
+ return vatnumber.check_vies(vat)
+
+ @api.model
def vies_vat_check(self, country_code, vat_number):
try:
# Validate against VAT Information Exchange System (VIES)
# see also http://ec.europa.eu/taxation_customs/vies/
- return vatnumber.check_vies(country_code.upper() + vat_number)
+ return self._check_vies(country_code.upper() + vat_number)
except Exception:
# see http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
# Fault code may contain INVALID_INPUT, SERVICE_UNAVAILABLE, MS_UNAVAILABLE,