From ecd252e48bb62d982d5c93a3381364cc7bf6c345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 10 May 2024 16:05:33 +0200 Subject: [PATCH] Raise user error when description of move template can not be formatted Closes #13240 --- modules/account/message.xml | 3 +++ modules/account/move_template.py | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/account/message.xml b/modules/account/message.xml index 57a27ae16a..34542b7ba2 100644 --- a/modules/account/message.xml +++ b/modules/account/message.xml @@ -139,6 +139,9 @@ this repository contains the full copyright notices and license terms. --> Use the current period to cancel the move? + + Failed to evaluate the description "%(description)s" from template "%(template)s" with error: "%(error)s" + Failed to evaluate expression "%(expression)s" from template "%(template)s" with error: "%(error)s" diff --git a/modules/account/move_template.py b/modules/account/move_template.py index e0ff2119b5..c548b8e981 100644 --- a/modules/account/move_template.py +++ b/modules/account/move_template.py @@ -55,8 +55,16 @@ class MoveTemplate(DeactivableMixin, ModelSQL, ModelView): move.company = self.company move.journal = self.journal if self.description: - move.description = self.description.format( - **dict(Keyword.format_values(self, values))) + try: + move.description = self.description.format( + **dict(Keyword.format_values(self, values))) + except (KeyError, ValueError) as e: + raise MoveTemplateExpressionError( + gettext( + 'account.msg_move_template_invalid_description', + description=self.description, + template=self.rec_name, + error=e)) from e move.lines = [l.get_line(values) for l in self.lines] return move