From 2e1689ef4745a9dedd123ee995b5f9b21c06d6e0 Mon Sep 17 00:00:00 2001 From: "Djamel (otd)" Date: Fri, 2 Apr 2021 08:16:53 +0000 Subject: [PATCH] [FIX] account: added a regex verification when adding a partner mapping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug : - Go to accounting > Configuration > Reconciliation Models - Create a new reconciliation model - Select the “Match existing invoices/bills” type - In the field “Match Invoice/bill with” choose “Label” - Add a new partner mapping > encode in "Find text in label" an erroneous regex like “*test” > choose any partner - Go to accounting Dashboard > click on “Bank” - Create a new Bank statement> add new transaction without selecting “Partner” - Post the created bank statements > Reconcile it Problem : An error is triggered because the regex is wrong. opw-2473973 closes odoo/odoo#68755 X-original-commit: cd9c071c9357cef14635ef094a9f14fc5431956c Signed-off-by: William André (wan) --- addons/account/i18n/account.pot | 7 +++++++ addons/account/models/account_reconcile_model.py | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 8e79d5ad58a..99222322b9e 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -11824,6 +11824,13 @@ msgid "" "don't have email address." msgstr "" +#. module: account +#: code:addons/account/models/account_reconcile_model.py:0 +#, python-format +msgid "" +"The following regular expression is invalid to create a partner mapping: %s" +msgstr "" + #. module: account #: code:addons/account/models/chart_template.py:0 #, python-format diff --git a/addons/account/models/account_reconcile_model.py b/addons/account/models/account_reconcile_model.py index 757702a1612..852ffc3851e 100644 --- a/addons/account/models/account_reconcile_model.py +++ b/addons/account/models/account_reconcile_model.py @@ -24,7 +24,15 @@ class AccountReconcileModelPartnerMapping(models.Model): for record in self: if not (record.narration_regex or record.payment_ref_regex): raise ValidationError(_("Please set at least one of the match texts to create a partner mapping.")) - + try: + if record.payment_ref_regex: + current_regex = record.payment_ref_regex + re.compile(record.payment_ref_regex) + if record.narration_regex: + current_regex = record.narration_regex + re.compile(record.narration_regex) + except re.error: + raise ValidationError(_("The following regular expression is invalid to create a partner mapping: %s") % current_regex) class AccountReconcileModelLine(models.Model): _name = 'account.reconcile.model.line'