From a9b3e90b781e3fa9058589311a8991337244f0f1 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Thu, 9 Jan 2020 22:57:35 +0100 Subject: Support new btw-identificatienummer The btw-identificatienummer has been introduced on January 1st 2020 in the Netherlands as an alternative to the btw-nummer that contains the BSN personal identifier. The number has the same structure and function but does not contain a BSN and uses a different check digit algorithm. Thanks to Cas Vissers, Jeroen van Heiningen, Jerome Hanke, Nicolas Martinelli, Ronald Portier and Tim Muller for contributing to the fix. More information: * http://kleineondernemer.nl/index.php/nieuw-btw-identificatienummer-vanaf-1-januari-2020-voor-eenmanszaken * https://nl.wikipedia.org/wiki/Btw-nummer_(Nederland) * https://www.belastingdienst.nl/wps/wcm/connect/bldcontenten/belastingdienst/business/vat/new-vat-id/ * https://www.belastingdienst.nl/wps/wcm/connect/bldcontentnl/belastingdienst/zakelijk/btw/administratie_bijhouden/btw_nummers_controleren/uw_btw_nummer Closes https://github.com/arthurdejong/python-stdnum/issues/182 Closes https://github.com/arthurdejong/python-stdnum/pull/183 Closes https://github.com/arthurdejong/python-stdnum/pull/184 Closes https://github.com/arthurdejong/python-stdnum/pull/185 --- stdnum/nl/btw.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'stdnum/nl') diff --git a/stdnum/nl/btw.py b/stdnum/nl/btw.py index 9485257..6d12372 100644 --- a/stdnum/nl/btw.py +++ b/stdnum/nl/btw.py @@ -1,6 +1,6 @@ # btw.py - functions for handling Dutch VAT numbers # -# Copyright (C) 2012, 2013 Arthur de Jong +# Copyright (C) 2012-2020 Arthur de Jong # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -17,11 +17,18 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301 USA -"""Btw-nummer (Omzetbelastingnummer, the Dutch VAT number). +"""Btw-identificatienummer (Omzetbelastingnummer, the Dutch VAT number). -The btw-nummer is the Dutch number for VAT. It consists of a RSIN or BSN -followed by the letter B and two digits that identify the unit within the -organisation (usually 01). +The btw-identificatienummer (previously the btw-nummer) is the Dutch number +for identifying parties in a transaction for which VAT is due. The btw-nummer +is used in communication with the tax agency while the +btw-identificatienummer (EORI-nummer) can be used when dealing with other +companies though they are used interchangeably. + +The btw-nummer consists of a RSIN or BSN followed by the letter B and two +digits that identify the number of the company created. The +btw-identificatienummer has a similar format but different checksum and does +not contain the BSN. More information: @@ -32,6 +39,8 @@ More information: '004495445B01' >>> validate('NL4495445B01') '004495445B01' +>>> validate('NL002455799B11') # valid since 2020-01-01 +'002455799B11' >>> validate('123456789B90') Traceback (most recent call last): ... @@ -39,6 +48,7 @@ InvalidChecksum: ... """ from stdnum.exceptions import * +from stdnum.iso7064 import mod_97_10 from stdnum.nl import bsn from stdnum.util import clean, isdigits @@ -53,21 +63,24 @@ def compact(number): def validate(number): - """Check if the number is a valid BTW number. This checks the length, + """Check if the number is a valid btw number. This checks the length, formatting and check digit.""" number = compact(number) + if not isdigits(number[:9]) or int(number[:9]) <= 0: + raise InvalidFormat() 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]) + if not bsn.is_valid(number[:9]) and not mod_97_10.is_valid('NL' + number): + raise InvalidChecksum() return number def is_valid(number): - """Check if the number is a valid BTW number.""" + """Check if the number is a valid btw number.""" try: return bool(validate(number)) except ValidationError: -- cgit v1.2.3