python-stdnum branch master updated. 2.2-11-g5fd7498
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 2.2-11-g5fd7498
- From: Commits of the python-stdnum project <python-stdnum-commits [at] lists.arthurdejong.org>
- To: python-stdnum-commits [at] lists.arthurdejong.org
- Reply-to: python-stdnum-users [at] lists.arthurdejong.org, python-stdnum-commits [at] lists.arthurdejong.org
- Subject: python-stdnum branch master updated. 2.2-11-g5fd7498
- Date: Sat, 15 Aug 2026 12:44:29 +0200 (CEST)
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".
The branch, master has been updated
via 5fd7498d8daa76277ea748d284c909bd38e5383f (commit)
from b0ce222e0c92d49403216e60181bbe535db52ac9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=5fd7498d8daa76277ea748d284c909bd38e5383f
commit 5fd7498d8daa76277ea748d284c909bd38e5383f
Author: Andrew Chi <17609957+gccbb02498@users.noreply.github.com>
Date: Tue Jul 7 16:04:44 2026 +0800
Support post 2023 Taiwan UBN numbers
The Ministry of Finance relaxed the UBN (統一編號) check digit logic
effective 2023-04-01 (民國112年): the weighted sum only needs to be
divisible by 5 instead of 10, to enlarge the pool of assignable numbers.
The special case for a 7 in the 7th position (allowing 1 to be added to
the sum) is preserved, now checked against divisibility by 5.
See:
https://www.fia.gov.tw/singlehtml/3?cntId=c4d9cff38c8642ef8872774ee9987283
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Closes https://github.com/arthurdejong/python-stdnum/pull/501
diff --git a/stdnum/tw/ubn.py b/stdnum/tw/ubn.py
index cf518cc..252e5ef 100644
--- a/stdnum/tw/ubn.py
+++ b/stdnum/tw/ubn.py
@@ -22,9 +22,14 @@ The Unified Business Number (UBN, 統一編號) is the number
assigned to busine
within Taiwan for tax (VAT) purposes. The number consists of 8 digits, the
last being a check digit.
+Since 2023-04-01 the Ministry of Finance relaxed the check digit logic so
+that the weighted sum only needs to be divisible by 5 (instead of 10) to
+increase the pool of available numbers.
+
More information:
* https://zh.wikipedia.org/wiki/統一編號
+* https://www.fia.gov.tw/singlehtml/3?cntId=c4d9cff38c8642ef8872774ee9987283
* https://findbiz.nat.gov.tw/fts/query/QueryBar/queryInit.do?request_locale=en
>>> validate('00501503')
@@ -61,7 +66,7 @@ def calc_checksum(number: str) -> int:
# convert to numeric first, then sum individual digits
weights = (1, 2, 1, 2, 1, 2, 4, 1)
number = ''.join(str(w * int(n)) for w, n in zip(weights, number))
- return sum(int(n) for n in number) % 10
+ return sum(int(n) for n in number) % 5
def validate(number: str) -> str:
@@ -75,7 +80,8 @@ def validate(number: str) -> str:
if not isdigits(number):
raise InvalidFormat()
checksum = calc_checksum(number)
- if not (checksum == 0 or (checksum == 9 and number[6] == '7')):
+ # if the 7th digit is 7 the check may also pass when adding 1 to the sum
+ if not (checksum == 0 or (checksum == 4 and number[6] == '7')):
raise InvalidChecksum()
return number
diff --git a/tests/test_tw_ubn.doctest b/tests/test_tw_ubn.doctest
index 06a4974..766ef65 100644
--- a/tests/test_tw_ubn.doctest
+++ b/tests/test_tw_ubn.doctest
@@ -45,6 +45,20 @@ Traceback (most recent call last):
InvalidChecksum: ...
+Since 2023-04-01 the check digit only needs the weighted sum to be divisible
+by 5 (instead of 10), so numbers that were invalid under the old rule may now
+be valid. The special case for a 7 in the 7th position still applies.
+
+>>> ubn.validate('10000004')
+'10000004'
+>>> ubn.validate('10000026')
+'10000026'
+>>> ubn.validate('10000073')
+'10000073'
+>>> ubn.validate('10000171')
+'10000171'
+
+
These have been found online and should all be valid numbers.
>>> numbers = '''
-----------------------------------------------------------------------
Summary of changes:
stdnum/tw/ubn.py | 10 ++++++++--
tests/test_tw_ubn.doctest | 14 ++++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
hooks/post-receive
--
python-stdnum
- python-stdnum branch master updated. 2.2-11-g5fd7498,
Commits of the python-stdnum project