summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Colson <oco@odoo.com>2018-10-30 16:46:55 +0100
committerOlivier Colson <oco@odoo.com>2018-10-30 16:46:55 +0100
commitd9448d738925d3d2deff33cec2ed134565c361e9 (patch)
tree4734df2f3f056b12dd57d20bc4c094f4c4bc637f
parent953dfe92c24ee02bad07ca454d94df16d9f5654c (diff)
[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.
-rw-r--r--addons/l10n_ch/models/res_bank.py6
1 files changed, 5 insertions, 1 deletions
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