Skip to content

fix(ec/ruc): do not enforce mod-11 check digit on company RUCs - #168

Open
menyinch wants to merge 1 commit into
koblas:mainfrom
menyinch:fix/ec-ruc-company-checksum
Open

fix(ec/ruc): do not enforce mod-11 check digit on company RUCs#168
menyinch wants to merge 1 commit into
koblas:mainfrom
menyinch:fix/ec-ruc-company-checksum

Conversation

@menyinch

Copy link
Copy Markdown
Contributor

Problem

EC.ruc.validate rejects real, registry-valid Ecuadorian company RUCs with InvalidChecksum. Example: 0993381661001 fails the mod-11 weighted sum ([4,3,2,7,6,5,4,3,2,1] → 159, 159 mod 11 = 5 ≠ 0) but is a valid taxpayer per SRI's official lookup (https://srienlinea.sri.gob.ec/sri-en-linea/SriRucWeb/ConsultaRuc/Consultas/consultaRuc).

Why

The mod-11 check-digit scheme for company RUCs is a historical/community algorithm. The SRI has clarified that RUCs issued to private companies (third digit 9), public companies (third digit 6), and foreign natural persons are not generated with any algorithm, and check-digit validation has never been a requirement — see the SRI statement quoted in https://minka.gob.ec/mintel/ge/rutr/gobec_forms/-/issues/32. The SRI's own e-invoicing scheme added an explicit exception to skip mod-11 validation for these numbers. Only cédula-based RUCs (third digit 0–5) carry a reliable check digit, because the cédula itself has one.

python-stdnum has the same issue; other implementations (e.g. Odoo's Ecuadorian localization) dropped the company-RUC checksum for this same reason.

Change

  • Third digit 6 (public) and 9 (juridical): skip the mod-11 checksum; keep structural validation (13 digits, valid province prefix, establishment number ≠ 0000/000). The 6-branch fallback to cédula validation is gone with the checksum that triggered it.
  • Third digit 0–5 (natural person): unchanged — still validates the cédula check digit via ec/ci.
  • Spec updated: the case 1792060347-001 asserted InvalidChecksum for an off-by-one tenth digit on a juridical RUC — that is exactly the false invariant, so it now asserts valid; added SRI-valid company RUCs (0993381661001, 1760001550001), an InvalidChecksum case on a natural-person RUC, and InvalidComponent cases (establishment 000/0000, bad province).

All 1641 tests pass; lint and prettier clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GgezMx4ZYyFgH8u4hgjsZ8

SRI issues public (third digit 6) and juridical (third digit 9) RUCs
without any check-digit algorithm, so the historical mod-11 scheme
rejects real registry-valid numbers (e.g. 0993381661001). Keep the
structural checks (length, province, establishment number) for company
RUCs and full cedula validation for natural-person RUCs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GgezMx4ZYyFgH8u4hgjsZ8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant