From 14cec1520b7cbc8e32c4d2549f7641a802c31b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 3 Apr 2026 17:06:49 +0200 Subject: [PATCH] Raise a generic user error message when failing to parse statement Closes #14621 --- modules/account_statement/message.xml | 3 +++ modules/account_statement/statement.py | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/account_statement/message.xml b/modules/account_statement/message.xml index 0ab682cc89..abd87e20d1 100644 --- a/modules/account_statement/message.xml +++ b/modules/account_statement/message.xml @@ -49,5 +49,8 @@ this repository contains the full copyright notices and license terms. --> To post the move "%(move)s" you must post the statement "%(statement)s". + + The statement file could not be parsed with the following exception: "%(exception)s". + diff --git a/modules/account_statement/statement.py b/modules/account_statement/statement.py index d8ec18ae40..c3d1e3d352 100644 --- a/modules/account_statement/statement.py +++ b/modules/account_statement/statement.py @@ -25,7 +25,8 @@ from trytond.transaction import Transaction from trytond.wizard import Button, StateAction, StateView, Wizard from .exceptions import ( - StatementPostError, StatementValidateError, StatementValidateWarning) + ImportStatementError, StatementPostError, StatementValidateError, + StatementValidateWarning) if config.getboolean('account_statement', 'filestore', default=False): file_id = 'origin_file_id' @@ -1281,7 +1282,15 @@ class ImportStatement(Wizard): def do_import_(self, action): pool = Pool() Statement = pool.get('account.statement') - statements = list(getattr(self, 'parse_%s' % self.start.file_format)()) + try: + statements = list( + getattr(self, 'parse_%s' % self.start.file_format)()) + except ImportStatementError: + raise + except Exception as exception: + raise ImportStatementError(gettext( + 'account_statement.msg_statement_import_error', + exception=exception)) from exception for statement in statements: statement.origin_file = fields.Binary.cast(self.start.file_) Statement.save(statements)