details:   https://code.tryton.org/tryton/commit/1d788729c663
branch:    default
user:      Cédric Krier <[email protected]>
date:      Fri Apr 03 17:06:49 2026 +0200
description:
        Raise a generic user error message when failing to parse statement

        Closes #14621
diffstat:

 modules/account_statement/message.xml  |   3 +++
 modules/account_statement/statement.py |  13 +++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diffs (42 lines):

diff -r 8337403b5d2e -r 1d788729c663 modules/account_statement/message.xml
--- a/modules/account_statement/message.xml     Fri Apr 03 15:56:14 2026 +0200
+++ b/modules/account_statement/message.xml     Fri Apr 03 17:06:49 2026 +0200
@@ -49,5 +49,8 @@
         <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>
diff -r 8337403b5d2e -r 1d788729c663 modules/account_statement/statement.py
--- a/modules/account_statement/statement.py    Fri Apr 03 15:56:14 2026 +0200
+++ b/modules/account_statement/statement.py    Fri Apr 03 17:06:49 2026 +0200
@@ -25,7 +25,8 @@
 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 @@
     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)

Reply via email to