From 1da003f4523369d982ad923e6ad5c3093dac298b Mon Sep 17 00:00:00 2001 From: Jeff Horemans Date: Fri, 17 May 2024 14:08:02 +0200 Subject: [PATCH] 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 --- stdnum/ch/uid.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/stdnum/ch/uid.py b/stdnum/ch/uid.py index 2131a12c..17fa776f 100644 --- a/stdnum/ch/uid.py +++ b/stdnum/ch/uid.py @@ -26,6 +26,8 @@ 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 @@ >>> 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 @@ 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):