lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.12-8-ga9b3e90

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.12-8-ga9b3e90



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".

The branch, master has been updated
       via  a9b3e90b781e3fa9058589311a8991337244f0f1 (commit)
      from  9605dbed3accf05c5e698f0d5d4b38a63b57f1c7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=a9b3e90b781e3fa9058589311a8991337244f0f1

commit a9b3e90b781e3fa9058589311a8991337244f0f1
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Thu Jan 9 22:57:35 2020 +0100

    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

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:
diff --git a/tests/test_eu_vat.doctest b/tests/test_eu_vat.doctest
index 4ea4cb2..d013f17 100644
--- a/tests/test_eu_vat.doctest
+++ b/tests/test_eu_vat.doctest
@@ -1,6 +1,6 @@
 test_eu_vat.doctest - more detailed doctests for the stdnum.eu.vat module
 
-Copyright (C) 2012-2017 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
@@ -562,8 +562,12 @@ These have been found online and should all be valid 
numbers.
 ... NL.0094.10.806.B.01
 ... NL.8143.26.584.B.01
 ... NL.8186.43.778.B.01
+... NL001162938B28
 ... NL001309675B01
+... NL001452330B47
 ... NL001545668B01
+... NL001617419B92
+... NL002455799B11
 ... NL003376734B77
 ... NL00449544B01
 ... NL006375054B01

-----------------------------------------------------------------------

Summary of changes:
 stdnum/nl/btw.py          | 29 +++++++++++++++++++++--------
 tests/test_eu_vat.doctest |  6 +++++-
 2 files changed, 26 insertions(+), 9 deletions(-)


hooks/post-receive
-- 
python-stdnum