From e951daca447f678f5a3f3c70dcc535eb8d7449b4 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Sun, 23 Jun 2024 16:12:59 +0200 Subject: Support 16 digit Indonesian NPWP numbers The Indonesian NPWP is being switched from 15 to 16 digits. The number is now the NIK for Indonesian citizens and the old format with a leading 0 for others (organisations and non-citizens). See https://www.grantthornton.co.id/insights/global-insights1/updates-regarding-the-format-of-indonesian-tax-id-numbers/ Closes https://github.com/arthurdejong/python-stdnum/issues/432 --- stdnum/id/npwp.py | 24 +++++++++++++++++++----- tests/test_id_npwp.doctest | 11 +++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/stdnum/id/npwp.py b/stdnum/id/npwp.py index cfa668c..effa8ec 100644 --- a/stdnum/id/npwp.py +++ b/stdnum/id/npwp.py @@ -2,6 +2,7 @@ # coding: utf-8 # # Copyright (C) 2020 Leandro Regueiro +# Copyright (C) 2024 Arthur de Jong # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -24,11 +25,15 @@ The Nomor Pokok Wajib Pajak (NPWP) is assigned to organisations and individuals (families) by the Indonesian Tax Office after registration by the tax payers. -The number consists of 15 digits of which the first 2 denote the type of +The number consists of 16 digits and is either a NIK (Nomor Induk Kependudukan) +or a number that starts with a 0, followed by 2 digits that denote the type of entity, 6 digits to identify the tax payer, a check digit over the first 8 digits followed by 3 digits to identify the local tax office and 3 digits for branch code. +This module also accepts the old 15 digit format which is just the 16 digit +format without the starting 0. + More information: * https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/Indonesia-TIN.pdf @@ -49,6 +54,7 @@ InvalidLength: ... from stdnum import luhn from stdnum.exceptions import * +from stdnum.id import nik from stdnum.util import clean, isdigits @@ -64,12 +70,20 @@ def compact(number): def validate(number): """Check if the number is a valid Indonesia NPWP number.""" number = compact(number) - if len(number) != 15: - raise InvalidLength() if not isdigits(number): raise InvalidFormat() - luhn.validate(number[:9]) - return number + if len(number) == 15: + # Old 15 digit format + luhn.validate(number[:9]) + return number + if len(number) == 16: + # New format since 2024: either a NIK (for Indonesian citizens) or + # the old number with a 0 at the beginning + if not number.startswith('0'): + return nik.validate(number) + luhn.validate(number[:10]) + return number + raise InvalidLength() def is_valid(number): diff --git a/tests/test_id_npwp.doctest b/tests/test_id_npwp.doctest index 13a78d9..621aa53 100644 --- a/tests/test_id_npwp.doctest +++ b/tests/test_id_npwp.doctest @@ -1,6 +1,7 @@ test_id_npwp.doctest - more detailed doctests for stdnum.id.npwp module Copyright (C) 2020 Leandro Regueiro +Copyright (C) 2024 Arthur de Jong This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -49,6 +50,16 @@ Traceback (most recent call last): InvalidChecksum: ... +Since 2024 the numbers have been changed to a 16 digit format. They can +either be a NIK (for Indonesian citizens) or a 0 followed by the original +15-digit number. + +>>> npwp.validate('3171011708450001') # NIK +'3171011708450001' +>>> npwp.validate('083.132.665.7-201.000') # extra 0 prepended +'0831326657201000' + + These have been found online and should all be valid numbers. >>> numbers = ''' -- cgit v1.2.3