[IMP] l10n_ch: also detect postal account type when using the shorten form with -
This shorten form is aa-bbb-x. The a characters are the first two digits of the number, x is the mod10r verification digit, and b characters consist of all the intermediate digits, without the leading 0s. The chain of b characters' length can range between 1 and 6 characters.
This commit is contained in:
@@ -10,8 +10,12 @@ from odoo.tools.misc import mod10r
|
||||
def _is_l10n_ch_postal(account_ref):
|
||||
""" Returns True iff the string account_ref is a valid postal account number,
|
||||
i.e. it only contains ciphers and is last cipher is the result of a recursive
|
||||
modulo 10 operation ran over the rest of it.
|
||||
modulo 10 operation ran over the rest of it. Shorten form with - is also accepted.
|
||||
"""
|
||||
if re.match('^[0-9]{2}-[0-9]{1,6}-[0-9]$', account_ref or ''):
|
||||
ref_subparts = account_ref.split('-')
|
||||
account_ref = ref_subparts[0] + ref_subparts[1].rjust(6,'0') + ref_subparts[2]
|
||||
|
||||
if re.match('\d+$', account_ref or ''):
|
||||
account_ref_without_check = account_ref[:-1]
|
||||
return mod10r(account_ref_without_check) == account_ref
|
||||
|
||||
Reference in New Issue
Block a user