[ADD] account_statement_import_txt_xlsx: show mapping error

If there is a problem parsing the file we are not showing the error
to the user, instead a generic message telling something is wrong
with the type of file is shown, and we only showing the error if
we are running unit tests.

In this case we think is good to show the error to the user, this
way they can check what is wrong and fix it in the sheet mapping.

* We are only showing the title of the error as a HINT, we think that is
  a good start to undestand what needs to change in the sheet mapping.
* The complete traceback error is shown in the log if we needed for more
  detail review from the technical teams.
This commit is contained in:
Katherine Zaoral
2022-11-12 09:00:18 -03:00
parent 91f32da7f1
commit 712301a964

View File

@@ -3,7 +3,8 @@
import logging
from odoo import fields, models
from odoo import _, fields, models
from odoo.exceptions import UserError
_logger = logging.getLogger(__name__)
@@ -32,10 +33,11 @@ class AccountStatementImport(models.TransientModel):
return Parser.parse(
data_file, self.sheet_mapping_id, self.statement_filename
)
except BaseException:
except BaseException as exc:
if self.env.context.get("account_statement_import_txt_xlsx_test"):
raise
_logger.warning("Sheet parser error", exc_info=True)
raise UserError(_("Bad file/mapping: ") + str(exc)) from exc
return super()._parse_file(data_file)
def _create_bank_statements(self, stmts_vals, result):