fix(cz/dic): correct special 9-digit DIC check to match python-stdnum (fixes #164) - #169
Open
youdie006 wants to merge 1 commit into
Open
fix(cz/dic): correct special 9-digit DIC check to match python-stdnum (fixes #164)#169youdie006 wants to merge 1 commit into
youdie006 wants to merge 1 commit into
Conversation
cz/dic checkSpecial (the special 9-digit DIC case, numbers starting with 6) diverged from the python-stdnum reference (cz/dic.py::calc_check_digit_special) two ways: (1) it included the leading 6 in the weighted sum (splitAt(value,-1) -> 8-digit front, weights [8,7,6,5,4,3,2,1]); the reference sums digits 2..8 only (number[1:8], weights [8,7,6,5,4,3,2]), excluding the leading 6 and the check digit. (2) the final reduction (8 - ((10 - sum) % 11)) % 10 relied on Python's non-negative modulo, but JS % keeps the dividend's sign, so a negative inner value yielded e.g. '-1' and never matched. As a result every special-case Czech VAT was falsely rejected via validate() -> InvalidChecksum. Drop the leading digit from the weighted sum, use weights [8,7,6,5,4,3,2], and compute the final digit with the existing pymod helper. Fixes koblas#164
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #164.
Root cause
cz/diccheckSpecial(the special 9-digit DIČ case, numbers starting with6) diverged from thepython-stdnumreference (cz/dic.py::calc_check_digit_special) in two ways:6in the weighted sum (splitAt(value, -1)-> 8-digit front, weights[8, 7, 6, 5, 4, 3, 2, 1]). The reference sums digits 2..8 only (number[1:8], weights[8, 7, 6, 5, 4, 3, 2]), excluding both the leading6and the check digit.(8 - ((10 - sum) % 11)) % 10relied on Python's always-non-negative modulo. JS%keeps the dividend's sign, so when the inner value is negative the computed digit becomes e.g."-1"and never matches.As a result every special-case Czech VAT (9-digit DIČ starting with
6) was falsely rejected viavalidate()->InvalidChecksum.Fix
Drop the leading digit from the weighted sum, use weights
[8, 7, 6, 5, 4, 3, 2], and compute the final digit with the existingpymodhelper (Python modulo).Verified valid VATs (accepted per the EU VIES service)
CZ687836437,CZ681208919(from the issue)640903926(python-stdnum's own doctest)699005400(VAT-group ID, format699nnnnnk, reported in the issue comment)Wrong check digit (
687836438) is still rejected, and normal non-special DIČ (e.g.CZ991231123, delegated tocz/rc) is unchanged.Testing
Red/green verified: reverting the fix fails exactly the four valid special VATs; with the fix all pass. Full Jest suite (200 suites / 1641 tests),
tsc --noEmit, and eslint all clean.This contribution was prepared with AI assistance (Claude); the change and tests were reviewed and verified locally.