summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorAndrea Grazioso (agr-odoo) <agr@odoo.com>2020-03-20 09:14:18 +0000
committerAndrea Grazioso (agr-odoo) <agr@odoo.com>2020-03-30 06:18:34 +0000
commit9d790bfb5ab8940f7092d427ce5c948c18400f3e (patch)
treed43d28c31f2f6a047091eb80dd033f7f4fc74dc5 /addons
parent04cc2b570003846f78ce6059d133b8e5ae000a4a (diff)
[FIX] base_vat: skip compacting if not vat of the country
Create a new contact with: - Name [DEMO] - VAT RORO790707I47 - Country Mexico An error inform the user that the vat is not valid, this happens because the vat number is recognized as romanian and compacted before passing to actual vat checking. Skip the check if the country of the new partner does not match what is detected on the vat, assuming the user know what he/she is doing opw-2218491 closes odoo/odoo#48273 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/base_vat/models/res_partner.py11
-rw-r--r--addons/base_vat/tests/test_validate_ruc.py9
2 files changed, 17 insertions, 3 deletions
diff --git a/addons/base_vat/models/res_partner.py b/addons/base_vat/models/res_partner.py
index d51b1e6a72f..b190fa606ee 100644
--- a/addons/base_vat/models/res_partner.py
+++ b/addons/base_vat/models/res_partner.py
@@ -468,8 +468,11 @@ class ResPartner(models.Model):
return False
return True
- def _fix_vat_number(self, vat):
+ def _fix_vat_number(self, vat, country_id):
+ code = self.env['res.country'].browse(country_id).code if country_id else False
vat_country, vat_number = self._split_vat(vat)
+ if code and code.lower() != vat_country:
+ return vat
stdnum_vat_fix_func = getattr(stdnum.util.get_cc_module(vat_country, 'vat'), 'compact', None)
#If any localization module need to define vat fix method for it's country then we give first priority to it.
format_func_name = 'format_vat_' + vat_country
@@ -481,10 +484,12 @@ class ResPartner(models.Model):
@api.model
def create(self, values):
if values.get('vat'):
- values['vat'] = self._fix_vat_number(values['vat'])
+ country_id = values.get('country_id')
+ values['vat'] = self._fix_vat_number(values['vat'], country_id)
return super(ResPartner, self).create(values)
def write(self, values):
if values.get('vat'):
- values['vat'] = self._fix_vat_number(values['vat'])
+ country_id = values.get('country_id', self.country_id.id)
+ values['vat'] = self._fix_vat_number(values['vat'], country_id)
return super(ResPartner, self).write(values)
diff --git a/addons/base_vat/tests/test_validate_ruc.py b/addons/base_vat/tests/test_validate_ruc.py
index c5c74a66cfd..32cf2edef15 100644
--- a/addons/base_vat/tests/test_validate_ruc.py
+++ b/addons/base_vat/tests/test_validate_ruc.py
@@ -20,6 +20,15 @@ class TestStructure(common.TransactionCase):
partner.vat = '11111111111'
partner.vat = '20507822470'
+ def test_vat_country_difference(self):
+ """Test the validation when country code is different from vat code"""
+ partner = self.env['res.partner'].create({
+ 'name': "Test",
+ 'country_id': self.env.ref('base.mx').id,
+ 'vat': 'RORO790707I47',
+ })
+ self.assertEqual(partner.vat, 'RORO790707I47', "Partner VAT should not be altered")
+
def test_parent_validation(self):
"""Test the validation with company and contact"""