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
498 stars 206 forks source link

New dutch VAT numbers should no longer always confirm to bsn format #182

Closed NL66278 closed 4 years ago

NL66278 commented 4 years ago

The first 9 digits of the vat number where validated for a check digit, like the bsn number that was part of it. However, this is no longer necessarily the case since 01-01-2020 (because of the privacy of self employed persons). Therefore this check should be removed.

Schrooms commented 4 years ago

More information can be found here(in dutch)

The new dutch VAT number is represented as follows: country code NL, 9 numbers, the letter 'B' and a check digit of 2 numbers. the 9 numbers are not bound to the bsn anymore. The check digit consist out of 2 random numbers.

Example: NL000099998B57

The check is now in btw.py

def validate(number):
    """Check if the number is a valid BTW number. This checks the length,
    formatting and check digit."""
    number = compact(number)
    if not isdigits(number[10:]) or int(number[10:]) <= 0:
        raise InvalidFormat()
    if len(number) != 12:
        raise InvalidLength()
    if number[9] != 'B':
        raise InvalidFormat()
    bsn.validate(number[:9])
    return number

by removing the bsn.validate(number[:9]) it will pass the new "regulations" .

def validate(number):
    """Check if the number is a valid BTW number. This checks the length,
    formatting and check digit."""
    number = compact(number)
    if not isdigits(number[10:]) or int(number[10:]) <= 0:
        raise InvalidFormat()
    if len(number) != 12:
        raise InvalidLength()
    if number[9] != 'B':
        raise InvalidFormat()
    return number
arthurdejong commented 4 years ago

Can someone provide me with some sample numbers of actual companies that are valid (i.e. pass the VIES VAT validation but do not pass the check algorithm in BSN. Thanks!

Schrooms commented 4 years ago

hi @arthurdejong. I send you one via the email

CasVissers-360ERP commented 4 years ago

Also see PR #183

nim-odoo commented 4 years ago

@Schrooms There should still be a validation algorithm for new numbers. #185 aims to implement it.

Schrooms commented 4 years ago

@Schrooms There should still be a validation algorithm for new numbers. #185 aims to implement it.

@nim-odoo yeah I really like #185 :+1: great work. Also can you tell me where this definition of the check can be found on the internet? (just curious) found it in your PR :smile:

arthurdejong commented 4 years ago

Thanks everyone for helping fix this. I've implemented the fix in a9b3e90. I will make a new release quickly.