[ADD] base_vat: VAT check for Venezuela
The current VAT check doesn't pass for valid Venezuelan VAT numbers (RIF). Venezuela has a specific method to validate their RIF, very different from the standard VIES check. This commit adds an implementation of the VAT number validation in Venezuela. The validation is based on (1) pattern matching (2) checksum validation Task id=3094593 closes odoo/odoo#110976 X-original-commit: 4fca8ed270c3406246e259b3aec7eda0b6d2d9ab Signed-off-by: Florian Gilbert (flg) <flg@odoo.com> Signed-off-by: Popeler Antoine (anpp) <anpp@odoo.com>
This commit is contained in:
@@ -74,6 +74,7 @@ _ref_vat = {
|
||||
'sk': 'SK2022749619',
|
||||
'sm': 'SM24165',
|
||||
'tr': 'TR1234567890 (VERGINO) or TR17291716060 (TCKIMLIKNO)', # Levent Karakas @ Eska Yazilim A.S.
|
||||
've': 'V-12345678-1, V123456781, V-12.345.678-1',
|
||||
'xi': 'XI123456782',
|
||||
}
|
||||
|
||||
@@ -562,6 +563,57 @@ class ResPartner(models.Model):
|
||||
res.append(False)
|
||||
return all(res)
|
||||
|
||||
def check_vat_ve(self, vat):
|
||||
# https://tin-check.com/en/venezuela/
|
||||
# https://techdocs.broadcom.com/us/en/symantec-security-software/information-security/data-loss-prevention/15-7/About-content-packs/What-s-included-in-Content-Pack-2021-02/Updated-data-identifiers-in-Content-Pack-2021-02/venezuela-national-identification-number-v115451096-d327e108002-CP2021-02.html
|
||||
# Sources last visited on 2022-12-09
|
||||
|
||||
# VAT format: (kind - 1 letter)(identifier number - 8-digit number)(check digit - 1 digit)
|
||||
vat_regex = re.compile(r"""
|
||||
([vecjpg]) # group 1 - kind
|
||||
(
|
||||
(?P<optional_1>-)? # optional '-' (1)
|
||||
[0-9]{2}
|
||||
(?(optional_1)(?P<optional_2>[.])?) # optional '.' (2) only if (1)
|
||||
[0-9]{3}
|
||||
(?(optional_2)[.]) # mandatory '.' if (2)
|
||||
[0-9]{3}
|
||||
(?(optional_1)-) # mandatory '-' if (1)
|
||||
) # group 2 - identifier number
|
||||
([0-9]{1}) # group X - check digit
|
||||
""", re.VERBOSE | re.IGNORECASE)
|
||||
|
||||
matches = re.fullmatch(vat_regex, vat)
|
||||
if not matches:
|
||||
return False
|
||||
|
||||
kind, identifier_number, *_, check_digit = matches.groups()
|
||||
kind = kind.lower()
|
||||
identifier_number = identifier_number.replace("-", "").replace(".", "")
|
||||
check_digit = int(check_digit)
|
||||
|
||||
if kind == 'v': # Venezuela citizenship
|
||||
kind_digit = 1
|
||||
elif kind == 'e': # Foreigner
|
||||
kind_digit = 2
|
||||
elif kind == 'c' or kind == 'j': # Township/Communal Council or Legal entity
|
||||
kind_digit = 3
|
||||
elif kind == 'p': # Passport
|
||||
kind_digit = 4
|
||||
else: # Government ('g')
|
||||
kind_digit = 5
|
||||
|
||||
# === Checksum validation ===
|
||||
multipliers = [3, 2, 7, 6, 5, 4, 3, 2]
|
||||
checksum = kind_digit * 4
|
||||
checksum += sum(map(lambda n, m: int(n) * m, identifier_number, multipliers))
|
||||
|
||||
checksum_digit = 11 - checksum % 11
|
||||
if checksum_digit > 9:
|
||||
checksum_digit = 0
|
||||
|
||||
return check_digit == checksum_digit
|
||||
|
||||
def check_vat_xi(self, vat):
|
||||
""" Temporary Nothern Ireland VAT validation following Brexit
|
||||
As of January 1st 2021, companies in Northern Ireland have a
|
||||
|
||||
Reference in New Issue
Block a user