Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions stdnum/ro/cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@

The Romanian CF is used for VAT purposes and can be from 2 to 10 digits long.

>>> validate('RO 185 472 90') # VAT CUI/CIF
'RO18547290'
>>> validate('RO 185 472 90') # VAT CUI/CIF (RO prefix is stripped)
'18547290'
>>> validate('RO RO 16621241')
Traceback (most recent call last):
...
InvalidFormat: ...
>>> validate('185 472 90') # non-VAT CUI/CIF
'18547290'
>>> validate('1630615123457') # CNP
Expand All @@ -32,13 +36,17 @@

from stdnum.exceptions import *
from stdnum.ro import cnp, cui
from stdnum.util import clean
from stdnum.util import clean, isdigits


def compact(number: str) -> str:
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
return clean(number, ' -').upper().strip()
number of any valid separators and removes surrounding whitespace. The
optional RO country prefix is removed to return the domestic form."""
number = clean(number, ' -').upper().strip()
if number.startswith('RO'):
number = number[2:]
return number


# for backwards compatibility
Expand All @@ -49,13 +57,12 @@ def validate(number: str) -> str:
"""Check if the number is a valid VAT number. This checks the length,
formatting and check digit."""
number = compact(number)
cnumber = number
if cnumber.startswith('RO'):
cnumber = cnumber[2:]
if len(cnumber) == 13:
if not isdigits(number):
raise InvalidFormat()
if len(number) == 13:
# apparently a CNP can also be used (however, not all sources agree)
cnp.validate(cnumber)
elif 2 <= len(cnumber) <= 10:
cnp.validate(number)
elif 2 <= len(number) <= 10:
cui.validate(number)
else:
raise InvalidLength()
Expand Down
Loading