arthurdejong / python-stdnum

A Python library to provide functions to handle, parse and validate standard numbers.
https://arthurdejong.org/python-stdnum/
GNU Lesser General Public License v2.1
484 stars 203 forks source link

Issues building compact representation for EU format #427

Closed DavideWalder closed 5 months ago

DavideWalder commented 5 months ago

To reproduce:

import stdnum.vatin

vat = "EU191849184"
assert stdnum.vatin.is_valid(vat)

stdnum.vatin.compact(vat)

Traceback:

.venv/lib/python3.11/site-packages/stdnum/vatin.py:77: in compact
    return number[:2] + module.compact(number[2:])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

number = '191849184'

    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()
        cc = number[:2]
        module = _get_cc_module(cc)
        if not module:
>           raise InvalidComponent()
E           stdnum.exceptions.InvalidComponent: One of the parts of the number are invalid or unknown.

It looks like it tries to retrieve the country code twice

arthurdejong commented 5 months ago

Thanks for pointing this out. I has been fixed in 1e412ee.