Skip to content

cz/dic rejects valid Czech VAT: checkSpecial differs from python-stdnum #164

Description

@marcos-cuentica

Root cause: a divergence between stdnum-js and python-stdnum in cz/dic (the special 9-digit case). These VAT numbers are valid per the official EU VIES service, but stdnum-js rejects them.

Examples: CZ687836437, CZ681208919

Details from Claude

Implementations of the Czech special case (9-digit DIČ starting with 6). In cz/dic checkSpecial the JS version includes the leading 6 in the weighted sum (splitAt(value, -1), weights [8,7,6,5,4,3,2,1]), while python-stdnum excludes the first and last digits (digits 2..8, weights [8,7,6,5,4,3,2]). With the python slicing, 687836437 validates and 687836438 (wrong check digit) is still rejected.

Follow-up: fixing only the slice isn't enough. The final formula
(8 - (10 - check) % 11) % 10 relies on Python's always-non-negative modulo.
In JS % takes the dividend's sign, so when (10 - check) % 11 > 8 the result
is negative and the check digit is wrong.

Example: CZ681208919 (valid per VIES) → intermediate 8 - 9 = -1;
Python -1 % 10 = 9 (correct), JS -1 % 10 = -1 (rejected).

Complete fix: const digit = ((8 - ((10 - sum) % 11)) % 10 + 10) % 10;

Version: 1.12.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions