fix try/except

This commit is contained in:
Luc De Meyer 2023-07-30 22:08:49 +02:00
parent 2a1a5ba73f
commit fdecfaaa37

View File

@ -393,12 +393,18 @@ class EbicsFile(models.Model):
) )
res = {"statement_ids": [], "notifications": []} res = {"statement_ids": [], "notifications": []}
st_datas = self._split_camt(res) st_datas = self._split_camt(res)
msg_hdr = _("{} : Import failed for file %(fn)s:\n", fn=self.name)
try:
if author == "oca": if author == "oca":
self._process_camt053_oca(res, st_datas) self._process_camt053_oca(res, st_datas)
else: else:
self._process_camt053_oe(res, st_datas) self._process_camt053_oe(res, st_datas)
return self._process_download_result(res)
def _process_camt053_oca(self, res, st_datas):
msg_hdr = _("{} : Import failed for file %(fn)s:\n", fn=self.name)
for st_data in st_datas:
try:
with self.env.cr.savepoint():
self._create_statement_camt053_oca(res, st_data)
except UserError as e: except UserError as e:
message = msg_hdr.format(_("Error")) message = msg_hdr.format(_("Error"))
message += "".join(e.args) message += "".join(e.args)
@ -409,13 +415,6 @@ class EbicsFile(models.Model):
message += tb message += tb
res["notifications"].append({"type": "error", "message": message}) res["notifications"].append({"type": "error", "message": message})
return self._process_download_result(res)
def _process_camt053_oca(self, res, st_datas):
for st_data in st_datas:
with self.env.cr.savepoint():
self._create_statement_camt053_oca(res, st_data)
def _create_statement_camt053_oca(self, res, st_data): def _create_statement_camt053_oca(self, res, st_data):
wiz = ( wiz = (
self.env["account.statement.import"] self.env["account.statement.import"]
@ -430,9 +429,20 @@ class EbicsFile(models.Model):
We execute a cr.commit() after every statement import since we get a We execute a cr.commit() after every statement import since we get a
'savepoint does not exist' error when using 'with self.env.cr.savepoint()'. 'savepoint does not exist' error when using 'with self.env.cr.savepoint()'.
""" """
msg_hdr = _("{} : Import failed for file %(fn)s:\n", fn=self.name)
for st_data in st_datas: for st_data in st_datas:
try:
self._create_statement_camt053_oe(res, st_data) self._create_statement_camt053_oe(res, st_data)
self.env.cr.commit() # pylint: disable=E8102 self.env.cr.commit() # pylint: disable=E8102
except UserError as e:
message = msg_hdr.format(_("Error"))
message += "".join(e.args)
res["notifications"].append({"type": "error", "message": message})
except Exception:
tb = "".join(format_exception(*exc_info()))
message = msg_hdr.format(_("Error"))
message += tb
res["notifications"].append({"type": "error", "message": message})
def _create_statement_camt053_oe(self, res, st_data): def _create_statement_camt053_oe(self, res, st_data):
attachment = ( attachment = (