From 5f39499892acb34368c119ab357935950826972e Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Mon, 13 Jun 2022 13:31:41 +0000 Subject: [PATCH] [FIX] base_vat: Fix vat number starting with 'EU' for not-EU companies Foreign companies that trade with non-enterprises in the EU may have a VATIN starting with "EU" instead of a country code. Currently, the user is facing a traceback in this situation since stdnum doesn't have any format method for vat number starting with 'EU'. closes odoo/odoo#93536 Ticket: 2877716 X-original-commit: 0f9f8409b379e3a0af28cecd3ed26829b9b26032 Signed-off-by: Olivier Colson (oco) Signed-off-by: Laurent Smet --- addons/base_vat/models/res_partner.py | 5 +++++ addons/base_vat/tests/test_validate_ruc.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/addons/base_vat/models/res_partner.py b/addons/base_vat/models/res_partner.py index 1cdba70ab11..6f4184f65c3 100644 --- a/addons/base_vat/models/res_partner.py +++ b/addons/base_vat/models/res_partner.py @@ -577,6 +577,11 @@ class ResPartner(models.Model): return len(vat) == 11 and vat.isdigit() return check_func(vat) + def format_vat_eu(self, vat): + # Foreign companies that trade with non-enterprises in the EU + # may have a VATIN starting with "EU" instead of a country code. + return vat + def format_vat_ch(self, vat): stdnum_vat_format = getattr(stdnum.util.get_cc_module('ch', 'vat'), 'format', None) return stdnum_vat_format('CH' + vat)[2:] if stdnum_vat_format else vat diff --git a/addons/base_vat/tests/test_validate_ruc.py b/addons/base_vat/tests/test_validate_ruc.py index 326b72f9a96..3cf9f73d640 100644 --- a/addons/base_vat/tests/test_validate_ruc.py +++ b/addons/base_vat/tests/test_validate_ruc.py @@ -80,6 +80,13 @@ class TestStructure(TransactionCase): # (for technical reasons due to ORM and res.company making related fields towards res.partner for country_id and vat) test_partner.write({'vat': '0477472701', 'country_id': None}) + def test_vat_eu(self): + """ Foreign companies that trade with non-enterprises in the EU may have a VATIN starting with "EU" instead of + a country code. + """ + test_partner = self.env['res.partner'].create({'name': "Turlututu", 'country_id': self.env.ref('base.fr').id}) + test_partner.write({'vat': "EU528003646", 'country_id': None}) + @tagged('-standard', 'external') class TestStructureVIES(TestStructure):