From d9448d738925d3d2deff33cec2ed134565c361e9 Mon Sep 17 00:00:00 2001 From: Olivier Colson Date: Tue, 30 Oct 2018 16:46:55 +0100 Subject: [PATCH] [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. --- addons/l10n_ch/models/res_bank.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/l10n_ch/models/res_bank.py b/addons/l10n_ch/models/res_bank.py index 28abbc7b058..24ac1792cfe 100644 --- a/addons/l10n_ch/models/res_bank.py +++ b/addons/l10n_ch/models/res_bank.py @@ -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