Raise a generic user error message when failing to parse statement

Closes #14621
This commit is contained in:
Cédric Krier
2026-04-03 17:06:49 +02:00
parent a936b768d0
commit 14cec1520b
2 changed files with 14 additions and 2 deletions
+3
View File
@@ -49,5 +49,8 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_post_statement_move">
<field name="text">To post the move "%(move)s" you must post the statement "%(statement)s".</field>
</record>
<record model="ir.message" id="msg_statement_import_error">
<field name="text">The statement file could not be parsed with the following exception: "%(exception)s".</field>
</record>
</data>
</tryton>
+11 -2
View File
@@ -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)