Skip to content
Snippets Groups Projects
Commit 6e8b3b97 authored by Jorge Pinna Puissant's avatar Jorge Pinna Puissant
Browse files

[FIX] base_vat: Correct management of the check of peruvian VAT without prefix.


partial backport of 88681f8f

opw-2171237

closes odoo/odoo#43497

X-original-commit: c3e097ff
Signed-off-by: default avatarJorge Pinna Puissant (jpp) <jpp@odoo.com>
parent 623988c9
No related branches found
No related tags found
No related merge requests found
......@@ -60,7 +60,7 @@ _ref_vat = {
'mx': 'ABC123456T1B',
'nl': 'NL123456782B90',
'no': 'NO123456785',
'pe': 'PER10254824220 or PED10254824220',
'pe': '10XXXXXXXXY or 20XXXXXXXXY or 15XXXXXXXXY or 16XXXXXXXXY or 17XXXXXXXXY',
'pl': 'PL1234567883',
'pt': 'PT123456789',
'ro': 'RO1234567897',
......@@ -293,38 +293,14 @@ class ResPartner(models.Model):
# Peruvian VAT validation, contributed by Vauxoo
def check_vat_pe(self, vat):
vat_type, vat = vat and len(vat) >= 2 and (vat[0], vat[1:]) or (False, False)
if vat_type and vat_type.upper() == 'D':
# DNI
return True
elif vat_type and vat_type.upper() == 'R':
# verify RUC
factor = '5432765432'
sum = 0
dig_check = False
if len(vat) != 11:
return False
try:
int(vat)
except ValueError:
return False
for f in range(0, 10):
sum += int(factor[f]) * int(vat[f])
subtraction = 11 - (sum % 11)
if subtraction == 10:
dig_check = 0
elif subtraction == 11:
dig_check = 1
else:
dig_check = subtraction
return int(vat[10]) == dig_check
else:
if len(vat) != 11 or not vat.isdigit():
return False
dig_check = 11 - (sum([int('5432765432'[f]) * int(vat[f]) for f in range(0, 10)]) % 11)
if dig_check == 10:
dig_check = 0
elif dig_check == 11:
dig_check = 1
return int(vat[10]) == dig_check
# VAT validation in Turkey, contributed by # Levent Karakas @ Eska Yazilim A.S.
def check_vat_tr(self, vat):
......
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_validate_ruc
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import common
from odoo.exceptions import ValidationError
class TestRUCStructure(common.TransactionCase):
def test_peru_ruc_format(self):
"""Only values that has the length of 11 will be checked as RUC, that's what we are proving. The second part
will check for a valid ruc and there will be no problem at all.
"""
partner = self.env['res.partner'].create({'name': "Dummy partner", 'country_id': self.env.ref('base.pe').id})
with self.assertRaises(ValidationError):
partner.vat = '11111111111'
partner.vat = '20507822470'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment