stdnum.tn.mf

MF (Matricule Fiscal, Tunisia tax number).

The MF consists of 4 parts: the “identifiant fiscal”, the “code TVA”, the “code catégorie” and the “numéro d’etablissement secondaire”.

The “identifiant fiscal” consists of 2 parts: the “identifiant unique” and the “clef de contrôle”. The “identifiant unique” is composed of 7 digits. The “clef de contrôle” is a letter, excluding “I”, “O” and “U” because of their similarity to “1”, “0” and “4”.

The “code TVA” is a letter that tells which VAT regime is being used. The valid values are “A”, “P”, “B”, “D” and “N”.

The “code catégorie” is a letter that tells the category the contributor belongs to. The valid values are “M”, “P”, “C”, “N” and “E”.

The “numéro d’etablissement secondaire” consists of 3 digits. It is usually “000”, but it can be “001”, “002”… depending on the branches. If it is not “000” then “code catégorie” must be “E”.

More information:

>>> validate('1234567/M/A/E/001')
'1234567MAE001'
>>> validate('1282182 W')
'1282182W'
>>> validate('121J')
'0000121J'
>>> validate('1219773U')
Traceback (most recent call last):
    ...
InvalidFormat: ...
>>> validate('1234567/M/A/X/000')
Traceback (most recent call last):
    ...
InvalidFormat: ...
>>> format('121J')
'0000121/J'
>>> format('1496298 T P N 000')
'1496298/T/P/N/000'
stdnum.tn.mf.compact(number)

Convert the number to the minimal representation.

This strips the number of any valid separators, removes surrounding whitespace.

stdnum.tn.mf.format(number)

Reformat the number to the standard presentation format.

stdnum.tn.mf.is_valid(number)

Check if the number is a valid Tunisia MF number.

stdnum.tn.mf.validate(number)

Check if the number is a valid Tunisia MF number.

This checks the length and formatting.