[FIX] base_vat: Use original version of stdnum for ecuadorian context
X-original-commit: 0f0402a8102626bf101e0ab9d25dadf9e934a6ed Part-of: odoo/odoo#77999
This commit is contained in:
@@ -262,60 +262,18 @@ class ResPartner(models.Model):
|
||||
return check == int(num[8])
|
||||
return False
|
||||
|
||||
def _checksum_ci_ec(self, number):
|
||||
"""Calculate a checksum over the number."""
|
||||
fold = lambda x: x - 9 if x > 9 else x
|
||||
return sum(fold((2, 1)[i % 2] * int(n))
|
||||
for i, n in enumerate(number)) % 10
|
||||
|
||||
def _checksum_ruc_ec(self, number, weights):
|
||||
"""Calculate a checksum over the number given the weights."""
|
||||
return sum(w * int(n) for w, n in zip(weights, number)) % 11
|
||||
|
||||
def is_valid_ci_ec(self, vat):
|
||||
"""Check if the number provided is a valid CI number. This checks the
|
||||
length, formatting and check digit."""
|
||||
if len(vat) != 10:
|
||||
return False
|
||||
if not vat.isdecimal():
|
||||
return False
|
||||
if (vat[:2] < '01' or vat[:2] > '24') and (vat[:2] not in ('30', '50')):
|
||||
return False
|
||||
if vat[2] > '6':
|
||||
return False
|
||||
if self._checksum_ci_ec(vat) != 0:
|
||||
return False
|
||||
return True
|
||||
|
||||
def is_valid_ruc_ec(self, vat):
|
||||
"""Check if the number provided is a valid RUC number. This checks the
|
||||
length, formatting, check digit and check sum."""
|
||||
if len(vat) != 13:
|
||||
return False
|
||||
if not vat.isdecimal():
|
||||
return False
|
||||
if (vat[:2] < '01' or vat[:2] > '24') and (vat[:2] not in ('30', '50')):
|
||||
return False
|
||||
if vat[2] <= '5':
|
||||
# 0..5 = natural RUC: CI plus establishment number
|
||||
if vat[-3:] == '000':
|
||||
return False
|
||||
return self.is_valid_ci_ec(vat[:10])
|
||||
elif vat[2] == '6':
|
||||
# 6 = public RUC
|
||||
#if vat[-4:] == '0000':
|
||||
# return False
|
||||
if self._checksum_ruc_ec(vat[:9], (3, 2, 7, 6, 5, 4, 3, 2, 1)) != 0:
|
||||
return False
|
||||
elif vat[2] == '9':
|
||||
# 9 = juridical RUC
|
||||
if vat[-3:] == '000':
|
||||
return False
|
||||
if self._checksum_ruc_ec(vat[:10], (4, 3, 2, 7, 6, 5, 4, 3, 2, 1)) != 0:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
ci = stdnum.util.get_cc_module("ec", "ci")
|
||||
ruc = stdnum.util.get_cc_module("ec", "ruc")
|
||||
if len(vat) == 10:
|
||||
return ci.is_valid(vat)
|
||||
elif len(vat) == 13:
|
||||
if vat[2] == "6" and ci.is_valid(vat[:10]):
|
||||
return True
|
||||
else:
|
||||
return ruc.is_valid(vat)
|
||||
return False
|
||||
|
||||
def check_vat_ec(self, vat):
|
||||
vat = clean(vat, ' -.').upper().strip()
|
||||
|
||||
Reference in New Issue
Block a user