Skip to content

Commit

Permalink
[IMP] base_vat_autocomplete: don't block the user with VIES service
Browse files Browse the repository at this point in the history
- When the VIES service is unreachable/unavailable, don't raise an error.
- Set the timeout to 5 seconds instead of default 120 seconds.

-task: 35043
  • Loading branch information
smetl authored and qdp-odoo committed Oct 17, 2017
1 parent 48c17fd commit c2f59f0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion addons/base_vat_autocomplete/models/res_partner.py
Expand Up @@ -6,6 +6,8 @@

from odoo import api, models

from suds.client import Client

_logger = logging.getLogger(__name__)

try:
Expand All @@ -14,6 +16,7 @@
_logger.warning('Python `stdnum` library not found, unable to call VIES service to detect address based on VAT number.')
stdnum_vat = None


class ResPartner(models.Model):
_inherit = 'res.partner'

Expand All @@ -40,7 +43,17 @@ def _check_city(lines, country='BE'):
if not partner.vat:
return {}
if len(partner.vat) > 5 and partner.vat[:2].lower() in stdnum_vat.country_codes:
result = stdnum_vat.check_vies(partner.vat)
# Equivalent to stdnum_vat.check_vies(partner.vat).
# However, we want to add a custom timeout to the suds.client
# because by default, it's 120 seconds and this is to long.
try:
client = Client(stdnum_vat.vies_wsdl, timeout=5)
partner_vat = stdnum_vat.compact(partner.vat)
result = client.service.checkVat(partner_vat[:2], partner_vat[2:])
except:
# Avoid blocking the client when the service is unreachable/unavailable
return {}

if not result['valid']:
return {}

Expand Down

0 comments on commit c2f59f0

Please sign in to comment.