Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] edi_state: do not break when no origin set #17

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion edi_state_oca/models/edi_state_consumer_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
# @author Simone Orsi <[email protected]>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import logging

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

_logger = logging.getLogger(__name__)


class EDIStateConsumerMixin(models.AbstractModel):
"""Provide specific EDI states for related records."""
Expand Down Expand Up @@ -34,7 +38,9 @@ def edi_is_valid_state(self, state=None, exc_type=None):
return True
# TODO: this implies we have `origin_exchange_type_id` from exchange.consumer.mixin
exc_type = exc_type or self.origin_exchange_type_id
assert exc_type, f"No exchange type given for {self._name}#{self.id}"
if not exc_type:
_logger.warning("No exchange type given for %s#%s", self._name, self.id)
return True
return (
state.workflow_id.is_valid_for_model(self._name)
and state.id in exc_type.state_workflow_ids.state_ids.ids
Expand Down
11 changes: 11 additions & 0 deletions edi_state_oca/tests/test_edi_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ def test_mixin_edi_set_state(self):
self.consumer_record.edi_find_state(code="OK_1"), self.wf1_ok.state_ids[0]
)

def test_mixin_edi_set_state_no_origin_pass_gracefully(self):
self.consumer_record.origin_exchange_record_id = False
logger_name = "odoo.addons.edi_state_oca.models.edi_state_consumer_mixin"
with self.assertLogs(logger_name, level="WARN") as logs:
self.consumer_record._edi_set_state(self.wf1_ok.state_ids[0])
err = (
f"No exchange type given for "
f"{self.consumer_record._name}#{self.consumer_record.id}"
)
self.assertIn(err, logs.output[0])

def test_mixin_edi_find_state(self):
with self.assertRaises(AssertionError):
self.assertEqual(self.consumer_model.edi_find_state())
Expand Down
Loading