Skip to content

Commit

Permalink
Merge PR #868 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by etobella
  • Loading branch information
OCA-git-bot committed Nov 22, 2023
2 parents 7a81753 + de59696 commit 9b2c442
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
32 changes: 18 additions & 14 deletions edi_oca/models/edi_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import base64
import logging
import traceback
from io import StringIO

from odoo import _, exceptions, fields, models, tools

Expand All @@ -17,10 +19,12 @@
_logger = logging.getLogger(__name__)


def _get_exception_msg(exc):
if hasattr(exc, "args") and isinstance(exc.args[0], str):
return exc.args[0]
return repr(exc)
def _get_exception_msg():
buff = StringIO()
traceback.print_exc(file=buff)
traceback_txt = buff.getvalue()
buff.close()
return traceback_txt


class EDIBackend(models.Model):
Expand Down Expand Up @@ -218,8 +222,8 @@ def exchange_generate(self, exchange_record, store=True, force=False, **kw):
if output:
try:
self._validate_data(exchange_record, output)
except EDIValidationError as err:
error = _get_exception_msg(err)
except EDIValidationError:
error = _get_exception_msg()
state = "validate_error"
message = exchange_record._exchange_status_message("validate_ko")
exchange_record.update(
Expand Down Expand Up @@ -281,10 +285,10 @@ def exchange_send(self, exchange_record):
message = None
try:
self._exchange_send(exchange_record)
except self._swallable_exceptions() as err:
except self._swallable_exceptions():
if self.env.context.get("_edi_send_break_on_error"):
raise
error = _get_exception_msg(err)
error = _get_exception_msg()
state = "output_error_on_send"
message = exchange_record._exchange_status_message("send_ko")
res = False
Expand Down Expand Up @@ -435,10 +439,10 @@ def exchange_process(self, exchange_record):
error = False
try:
self._exchange_process(exchange_record)
except self._swallable_exceptions() as err:
except self._swallable_exceptions():
if self.env.context.get("_edi_process_break_on_error"):
raise
error = _get_exception_msg(err)
error = _get_exception_msg()
state = "input_processed_error"
res = False
else:
Expand Down Expand Up @@ -487,15 +491,15 @@ def exchange_receive(self, exchange_record):
if content:
exchange_record._set_file_content(content)
self._validate_data(exchange_record)
except EDIValidationError as err:
error = _get_exception_msg(err)
except EDIValidationError:
error = _get_exception_msg()
state = "validate_error"
message = exchange_record._exchange_status_message("validate_ko")
res = False
except self._swallable_exceptions() as err:
except self._swallable_exceptions():
if self.env.context.get("_edi_receive_break_on_error"):
raise
error = _get_exception_msg(err)
error = _get_exception_msg()
state = "input_receive_error"
message = exchange_record._exchange_status_message("receive_ko")
res = False
Expand Down
2 changes: 1 addition & 1 deletion edi_oca/tests/test_backend_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def test_send_record_with_error(self):
[
{
"edi_exchange_state": "output_error_on_send",
"exchange_error": "OOPS! Something went wrong :(",
}
],
)
self.assertIn("OOPS! Something went wrong :(", self.record.exchange_error)

def test_send_invalid_direction(self):
vals = {
Expand Down
2 changes: 1 addition & 1 deletion edi_oca/tests/test_backend_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ def test_process_record_with_error(self):
[
{
"edi_exchange_state": "input_processed_error",
"exchange_error": "OOPS! Something went wrong :(",
}
],
)
self.assertIn("OOPS! Something went wrong :(", self.record.exchange_error)

@mute_logger("odoo.models.unlink")
def test_process_no_file_record(self):
Expand Down
4 changes: 2 additions & 2 deletions edi_oca/tests/test_backend_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ def test_receive_validate_record_error(self):
[
{
"edi_exchange_state": "validate_error",
"exchange_error": "Data seems wrong!",
}
],
)
self.assertIn("Data seems wrong!", self.record_in.exchange_error)

def test_generate_validate_record(self):
self.record_out.write({"edi_exchange_state": "new"})
Expand All @@ -87,7 +87,7 @@ def test_generate_validate_record_error(self):
[
{
"edi_exchange_state": "validate_error",
"exchange_error": "Data seems wrong!",
}
],
)
self.assertIn("Data seems wrong!", self.record_out.exchange_error)

0 comments on commit 9b2c442

Please sign in to comment.