diff --git a/stdnum/ro/cf.py b/stdnum/ro/cf.py index 918df30a..f0511106 100644 --- a/stdnum/ro/cf.py +++ b/stdnum/ro/cf.py @@ -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 @@ -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 @@ -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()