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
21 changes: 11 additions & 10 deletions stdnum/ro/cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

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('185 472 90') # non-VAT CUI/CIF
'18547290'
>>> validate('1630615123457') # CNP
Expand All @@ -37,8 +37,12 @@

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 +53,10 @@ 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 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