[FIX] base_vat: ID vat validation

Recently, the vat validation was changed to
support 16 digits vat introduced in Indonesia
in January 2024.
This change replaced the stdnum validation,
but did not handle vat numbers written using
the standard presentation format.

This is fixed here, where we will remove the
characters used in this format and strip the
vat before doing the validation on the digit
amount.

closes odoo/odoo#148386

X-original-commit: 4c8629228f7842501d5a067451abca24d1089bf9
Signed-off-by: Josse Colpaert <jco@odoo.com>
Signed-off-by: Nicolas Viseur (vin) <vin@odoo.com>
This commit is contained in:
Nicolas Viseur (vin)
2024-01-07 02:52:21 +00:00
parent 0e23020b84
commit 1c8a0824da
+14 -4
View File
@@ -7,8 +7,9 @@ import zeep
import re
import stdnum
from stdnum.eu.vat import check_vies
from stdnum.exceptions import InvalidComponent
from stdnum.exceptions import InvalidComponent, InvalidChecksum, InvalidFormat
from stdnum.util import clean
from stdnum import luhn
import logging
@@ -741,9 +742,18 @@ class ResPartner(models.Model):
def check_vat_id(self, vat):
""" Temporary Indonesian VAT validation to support the new format
introduced in January 2024."""
if len(vat) in (15, 16) and vat[0:15].isdigit() and vat[-1].isdigit():
return True
return False
vat = clean(vat, ' -.').strip()
if len(vat) not in (15, 16) or not vat[0:15].isdecimal() or not vat[-1].isdecimal():
return False
# VAT is only digits and of the right length, check the Luhn checksum.
try:
luhn.validate(vat[0:9])
except (InvalidFormat, InvalidChecksum):
return False
return True
def format_vat_sm(self, vat):
stdnum_vat_format = stdnum.util.get_cc_module('sm', 'vat').compact