diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-10-20 17:57:21 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-10-20 17:57:21 +0200 |
| commit | 5ea0f55d654f4c4c928fa1c4ea3ebcf7d1613812 (patch) | |
| tree | ce5bb069ae0d18c882b9ed707bddf36a987bc913 /addons/base_vat/models | |
| parent | 635572b49d5b70a32b717cf2d52da49b10aac28e (diff) | |
| parent | bee0c11ef7fdd2f289b1b5d33bf4574e519d8fcf (diff) | |
[MERGE] forward port branch saas-15 up to bee0c11ef7f
Diffstat (limited to 'addons/base_vat/models')
| -rw-r--r-- | addons/base_vat/models/res_partner.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/addons/base_vat/models/res_partner.py b/addons/base_vat/models/res_partner.py index 1de5c95aeab..69d7204bf9a 100644 --- a/addons/base_vat/models/res_partner.py +++ b/addons/base_vat/models/res_partner.py @@ -18,6 +18,12 @@ from odoo import api, models, _ from odoo.tools.misc import ustr from odoo.exceptions import ValidationError +_eu_country_vat = { + 'GR': 'EL' +} + +_eu_country_vat_inverse = {v: k for k, v in _eu_country_vat.items()} + _ref_vat = { 'at': 'ATU12345675', 'be': 'BE0477472701', @@ -79,6 +85,7 @@ class ResPartner(models.Model): # Foreign companies that trade with non-enterprises in the EU # may have a VATIN starting with "EU" instead of a country code. return True + country_code = _eu_country_vat_inverse.get(country_code, country_code) return bool(self.env['res.country'].search([('code', '=ilike', country_code)])) return check_func(vat_number) @@ -96,6 +103,19 @@ class ResPartner(models.Model): # country code or empty VAT number), so we fall back to the simple check. return self.simple_vat_check(country_code, vat_number) + @api.model + def fix_eu_vat_number(self, country_id, vat): + europe = self.env.ref('base.europe') + country = self.env["res.country"].browse(country_id) + if not europe: + europe = self.env["res.country.group"].search([('name', '=', 'Europe')], limit=1) + if europe and country and country.id in europe.country_ids.ids: + vat = re.sub('[^A-Za-z0-9]', '', vat).upper() + country_code = _eu_country_vat.get(country.code, country.code).upper() + if vat[:2] != country_code: + vat = country_code + vat + return vat + @api.constrains('vat', 'commercial_partner_country_id') def check_vat(self): if self.env.context.get('company_id'): |
