feat(cnpj): add alphanumeric CNPJ support (RFB Nota Técnica 49/2024)#730
Closed
gugacyber wants to merge 1 commit into
Closed
feat(cnpj): add alphanumeric CNPJ support (RFB Nota Técnica 49/2024)#730gugacyber wants to merge 1 commit into
gugacyber wants to merge 1 commit into
Conversation
The Receita Federal will start issuing alphanumeric CNPJs in July 2026, per Nota Técnica Conjunta COCAD/SUARA/RFB nº 49/2024. Changes: - _char_value(): new helper converting chars via ord(c)-48 (RFB rule) - _is_valid_format(): centralised format check supporting [0-9A-Z] - _hashdigit(): uses _char_value() instead of int() — works for both - validate() / is_valid(): accept 14-char alphanumeric CNPJs - display() / format_cnpj(): format alphanumeric CNPJs correctly - generate(): new alphanumeric=False parameter for backward compat - All existing tests pass (10/10); 10 new tests added (20/20 total) Closes brazilian-utils#685
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #730 +/- ##
==========================================
- Coverage 99.08% 98.84% -0.24%
==========================================
Files 26 26
Lines 765 782 +17
==========================================
+ Hits 758 773 +15
- Misses 7 9 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
olá! agradecemos pela sua contribuição, porém, já tem uma pessoa responsável por essa issue e com um pr aberto pra revisão.. por esse motivo esse pr vai ser fechado sem revisão. |
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.
Summary
Closes #685
Implements support for the new alphanumeric CNPJ format introduced by the Receita Federal do Brasil, effective July 2026 (Nota Técnica Conjunta COCAD/SUARA/RFB nº 49/2024).
Background
Starting July 2026, the RFB will issue CNPJs where the first 12 characters (base + branch) can contain uppercase letters A–Z in addition to digits 0–9. The two check digits (DVs) remain numeric. The validation algorithm is unchanged but character values are computed as
ord(char) - 48instead ofint(char).Changes
brutils/cnpj.pytests/test_cnpj.pyNew helper:
_char_value(char)Converts a character to its RFB numeric value (
ord(char) - 48):'0'–'9'→ 0–9'A'–'Z'→ 17–42Updated:
_hashdigit()Uses
_char_value()instead ofint()— fully backward compatible.Updated:
validate()/is_valid()Accept 14-character strings containing
[0-9A-Z]with numeric DVs.Updated:
generate()New
alphanumeric=Falseparameter. Defaults toFalsefor backward compatibility.Tests
New test cases: