Skip to content

Add support for Mozambique TIN (CUIT) #473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

lucasicr
Copy link
Contributor

@lucasicr lucasicr commented May 10, 2025

Fixes #360
Based on #392

  • Invalid CUIT numbers have been removed from the test.
  • Checksum algorithm added

Source

In the following government webpage it is effectively possible to check the validity of CUIT numbers.
https://nuit.at.gov.mz/nuit/bootstrap/theme/work/Impressao_Carta.aspx

To validate a CUIT the user should enter it in the first field (without any separation characters) and either enter a date in the second field or check "NUIT COLECTIVO". He can then press the blue button with written "Pesquisar"

  1. When an invalid CUIT is entered, the user is redirected back to webpage were he has entered the wrong CUIT and the following error message is displayed in red: "NUIT Inválido"
  2. When a valid CUIT is entered, the user is redirected to a different webpage, where:
    2.1. if an incorrect birth date was entered, this error message is showed in light red: "Por favor, dirija-se a uma Unidade Orgânica da Autoridade Tributária afim de resolver problemas de validação do seu NUIT."
    2.2. if the entered date was correct, or "NUIT COLECTIVO" was selected, the user is redirected to a page where he can download a document that certifies that that CUIT number was issued on a certain date to a certain individual or company.

CUIT doctest

From the numbers incluced in the doctest in #392, every one is considered valid from the above website, except two:

  • 101935626
  • 400380972
    Since this could be easily explained by there being a typo in these two instances (2 out of 86), the above numbers have been excluded from the doctest.

Checksum validation

The checksum algorithm has been reverse engineered from the above website as follows:

The checksum of a given number can be determined by trial and error.
Comparing the checksum of numbers differing by only one digit, it turns out to follow a regular sequence of 11 digits:
the sequence for the first digit is the same as taking every 8th digit from the number 01234567891 (looping back when necessary), for the second digit you take every 9th number, for the third every 4th and so on. These are the weights in the mod 11 algorithm.

def calc_check_digit(number: str) -> str:
    """Calculate the check digit. The number passed should not have
    the check digit included."""
    weights = (8, 9, 4, 5, 6, 7, 8, 9)
    check = sum(w * int(n) for w, n in zip(weights, number)) % 11
    return '01234567891'[check]

The algorithm obtained by the above method was checked against the numbers in the doctest. Also a collection of randomly generated numbers with the check digit calculated by the algorithm have been checked on the above website.

unho and others added 5 commits February 5, 2023 18:52

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Update nuit.py

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Added checksum test
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.

Add support for Mozambique TIN
2 participants