lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.20-6-g1da003f

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

python-stdnum branch master updated. 1.20-6-g1da003f



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  1da003f4523369d982ad923e6ad5c3093dac298b (commit)
      from  91959bdb463d2a518c928fe07f7e7502daa82725 (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=1da003f4523369d982ad923e6ad5c3093dac298b

commit 1da003f4523369d982ad923e6ad5c3093dac298b
Author: Jeff Horemans <jeff.horemans@vortex-financials.be>
Date:   Fri May 17 14:08:02 2024 +0200

    Adjust Swiss uid module to accept numbers without CHE prefix
    
    Closes https://github.com/arthurdejong/python-stdnum/pull/437
    Closes https://github.com/arthurdejong/python-stdnum/issues/423

diff --git a/stdnum/ch/uid.py b/stdnum/ch/uid.py
index 2131a12..17fa776 100644
--- a/stdnum/ch/uid.py
+++ b/stdnum/ch/uid.py
@@ -26,6 +26,8 @@ protected with a simple checksum.
 
 This module only supports the "new" format that was introduced in 2011 which
 completely replaced the "old" 6-digit format in 2014.
+Stripped numbers without the CHE prefix are allowed and validated,
+but are returned with the prefix prepended.
 
 More information:
 
@@ -34,6 +36,8 @@ More information:
 
 >>> validate('CHE-100.155.212')
 'CHE100155212'
+>>> validate('100.155.212')
+'CHE100155212'
 >>> validate('CHE-100.155.213')
 Traceback (most recent call last):
     ...
@@ -49,7 +53,10 @@ from stdnum.util import clean, get_soap_client, isdigits
 def compact(number):
     """Convert the number to the minimal representation. This strips
     surrounding whitespace and separators."""
-    return clean(number, ' -.').strip().upper()
+    number = clean(number, ' -.').strip().upper()
+    if len(number) == 9 and isdigits(number):
+        number = 'CHE' + number
+    return number
 
 
 def calc_check_digit(number):

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

Summary of changes:
 stdnum/ch/uid.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)


hooks/post-receive
-- 
python-stdnum