diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2020-11-01 16:46:28 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2020-11-01 17:27:08 +0100 |
commit | c5eb2d89ae93bf3960f50f4a6f09e6aa022250a9 (patch) | |
tree | c9cc3e7d467b17b74f78098609fba395938935fb | |
parent | 1f6c77fdc222b44ad8f371b48923d9179ab59e3e (diff) |
Retain RO prefix in Romanian VAT numbers
This does not strip the RO prefix from Romanian VAT numbers to be able
to keep the distinction between a CUI/CIF that is registered for VAT
(which commonly has the RO prefix) and those that don't.
Closes https://github.com/arthurdejong/python-stdnum/issues/231
-rw-r--r-- | stdnum/eu/vat.py | 16 | ||||
-rw-r--r-- | stdnum/ro/cf.py | 18 | ||||
-rw-r--r-- | tests/test_eu_vat.doctest | 7 |
3 files changed, 28 insertions, 13 deletions
diff --git a/stdnum/eu/vat.py b/stdnum/eu/vat.py index 987d8fc..27d47c6 100644 --- a/stdnum/eu/vat.py +++ b/stdnum/eu/vat.py @@ -74,20 +74,28 @@ def compact(number): """Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.""" number = clean(number, '').upper().strip() - module = _get_cc_module(number[:2]) + cc = number[:2] + module = _get_cc_module(cc) if not module: raise InvalidComponent() - return number[:2] + module.compact(number[2:]) + number = module.compact(number) + if not number.startswith(cc): + number = cc + number + return number def validate(number): """Check if the number is a valid VAT number. This performs the country-specific check for the number.""" number = clean(number, '').upper().strip() - module = _get_cc_module(number[:2]) + cc = number[:2] + module = _get_cc_module(cc) if not module: raise InvalidComponent() - return number[:2] + module.validate(number[2:]) + number = module.validate(number) + if not number.startswith(cc): + number = cc + number + return number def is_valid(number): diff --git a/stdnum/ro/cf.py b/stdnum/ro/cf.py index 4bf1d8f..7c8006f 100644 --- a/stdnum/ro/cf.py +++ b/stdnum/ro/cf.py @@ -23,7 +23,7 @@ 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 -'18547290' +'RO18547290' >>> validate('185 472 90') # non-VAT CUI/CIF '18547290' >>> validate('1630615123457') # CNP @@ -38,10 +38,7 @@ from stdnum.util import clean def compact(number): """Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.""" - number = clean(number, ' -').upper().strip() - if number.startswith('RO'): - number = number[2:] - return number + return clean(number, ' -').upper().strip() # for backwards compatibility @@ -52,11 +49,14 @@ def validate(number): """Check if the number is a valid VAT number. This checks the length, formatting and check digit.""" number = compact(number) - if len(number) == 13: + cnumber = number + if cnumber.startswith('RO'): + cnumber = cnumber[2:] + if len(cnumber) == 13: # apparently a CNP can also be used (however, not all sources agree) - cnp.validate(number) - elif 2 <= len(number) <= 10: - cui.validate(number) + cnp.validate(cnumber) + elif 2 <= len(cnumber) <= 10: + cui.validate(cnumber) else: raise InvalidLength() return number diff --git a/tests/test_eu_vat.doctest b/tests/test_eu_vat.doctest index d013f17..362f1de 100644 --- a/tests/test_eu_vat.doctest +++ b/tests/test_eu_vat.doctest @@ -912,3 +912,10 @@ These numbers should be mostly valid except that they have the wrong length. ... ''' >>> [x for x in numbers.splitlines() if x and not caught(x, InvalidLength)] [] + + +Romanian CIF numbers assume that the RO prefix is part of the number so the +EU VAT module should not return the prefix twice. + +>>> vat.compact('RO 21996566') +'RO21996566' |