[FIX] base_vat,l10n_ph: correct TIN check

Register a ph contact with vat 123-456-789-012
Validation Error will raise

Currently we use check the PH vat against regexp \d{3}-\d{3}-\d{3}-\d{5}
This seems to be not correct according to the official documentation
https://serp-p.pids.gov.ph/publication/public/view?slug=taxpayer-identification-number-tin-its-development-and-importance-in-tax-administration

"""
12 digit number (E.g. 123 456 789 002), of which the first digit
identifies type of taxpayer (0 for corporations, 1-9 for individuals
and other businesses), second to eighth digits are sequential numbers
between 0 and 9, ninth digit is a check number, last three digits are
000 for individuals and head office of businesses and 001-999 for
branches of businesses, if any
"""

The TIN should be a 9 digit code + 3 for the branch code

opw-3141793

closes odoo/odoo#116491

X-original-commit: f0e9a3ce7fec9bb86b8703a6d49c0bc70c80d5c3
Signed-off-by: Josse Colpaert <jco@odoo.com>
Signed-off-by: Grazioso Andrea (agr) <agr@odoo.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2023-03-28 18:45:47 +02:00
parent a5ca1895ac
commit 27cdc052dd
2 changed files with 16 additions and 7 deletions
+7 -1
View File
@@ -63,7 +63,7 @@ _ref_vat = {
'no': 'NO123456785',
'nz': '49-098-576 or 49098576',
'pe': '10XXXXXXXXY or 20XXXXXXXXY or 15XXXXXXXXY or 16XXXXXXXXY or 17XXXXXXXXY',
'ph': '123-456-789-01234',
'ph': '123-456-789-123',
'pl': 'PL1234567883',
'pt': 'PT123456789',
'ro': 'RO1234567897',
@@ -499,6 +499,12 @@ class ResPartner(models.Model):
dig_check = 1
return int(vat[10]) == dig_check
# Philippines TIN (+ branch code) validation
__check_vat_ph_re = re.compile(r"\d{3}-\d{3}-\d{3}(-\d{3,5})?$")
def check_vat_ph(self, vat):
return len(vat) >= 11 and len(vat) <= 17 and self.__check_vat_ph_re.match(vat)
def check_vat_ru(self, vat):
'''
Check Russia VAT number.
+9 -6
View File
@@ -1,15 +1,12 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import re
from odoo import fields, api, models
CHECK_VAT_PH_RE = re.compile(r"\d{3}-\d{3}-\d{3}-\d{5}")
class ResPartner(models.Model):
_inherit = "res.partner"
branch_code = fields.Char("Branch Code", default='000', required=True)
branch_code = fields.Char("Branch Code", default='000', compute='_compute_branch_code', store=True)
first_name = fields.Char("First Name")
middle_name = fields.Char("Middle Name")
last_name = fields.Char("Last Name")
@@ -18,5 +15,11 @@ class ResPartner(models.Model):
def _commercial_fields(self):
return super()._commercial_fields() + ['branch_code']
def check_vat_ph(self, vat):
return len(vat) == 17 and CHECK_VAT_PH_RE.match(vat)
@api.depends('vat', 'country_id')
def _compute_branch_code(self):
for partner in self:
branch_code = '000'
if partner.country_id.code == 'PH' and partner.vat:
match = partner.__check_vat_ph_re.match(partner.vat)
branch_code = match and match.group(1) and match.group(1)[1:] or branch_code
partner.branch_code = branch_code