Raise user error when description of move template can not be formatted

Closes #13240
This commit is contained in:
Cédric Krier
2024-05-10 16:05:33 +02:00
parent 06270e6a7a
commit ecd252e48b
2 changed files with 13 additions and 2 deletions
+3
View File
@@ -139,6 +139,9 @@ this repository contains the full copyright notices and license terms. -->
Use the current period to cancel the move?</field>
</record>
<record model="ir.message" id="msg_move_template_invalid_description">
<field name="text">Failed to evaluate the description "%(description)s" from template "%(template)s" with error: "%(error)s"</field>
</record>
<record model="ir.message" id="msg_move_template_invalid_expression">
<field name="text">Failed to evaluate expression "%(expression)s" from template "%(template)s" with error:
"%(error)s"</field>
+10 -2
View File
@@ -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