Skip to content
Open
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
6 changes: 1 addition & 5 deletions component/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ def vocalize(action, message):
def __init__(self, work_context):
super().__init__()
self.work = work_context
self.env = work_context.env

@classmethod
def _component_match(cls, work, usage=None, model_name=None, **kw):
Expand Down Expand Up @@ -726,11 +727,6 @@ def collection(self):
"""Collection we are working with"""
return self.work.collection

@property
def env(self):
"""Current Odoo environment, the one of the collection record"""
return self.work.env

@property
def model(self):
"""The model instance we are working with"""
Expand Down
13 changes: 11 additions & 2 deletions component/tests/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ def tearDown(self):
self._teardown_registry(self)
super().tearDown()

def _setUpComponents(self):
def _setUpComponents(self): # pylint: disable=missing-return
# create some Component to play with
class Component1(Component):
_name = "component1"
_collection = "collection.base"
_usage = "for.test"
_apply_on = ["res.partner"]

def __init__(self, work_context):
super().__init__(work_context)
self.env = self.env(context=dict(self.env.context, foo="bar"))

class Component2(Component):
_name = "component2"
_collection = "collection.base"
Expand All @@ -51,6 +55,10 @@ class Component2(Component):
# our collection, in a less abstract use case, it
# could be a record of 'magento.backend' for instance
self.collection_record = self.collection.new()
# add ctx key to ensure it's preserved later
self.collection_record = self.collection_record.with_context(
from_collection=True
)

@contextmanager
def get_base():
Expand Down Expand Up @@ -78,7 +86,8 @@ def test_component_attrs(self):
# but this is not what we test here, we test the attributes:
self.assertEqual(self.collection_record, comp.collection)
self.assertEqual(base.work, comp.work)
self.assertEqual(self.env, comp.env)
self.assertEqual(comp.env.context["from_collection"], True)
self.assertEqual(comp.env.context["foo"], "bar")
self.assertEqual(self.env["res.partner"], comp.model)

def test_component_get_by_name_same_model(self):
Expand Down