Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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: 3 additions & 3 deletions shopfloor_reception/services/reception.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _scheduled_date_today_domain(self):
return domain

def _get_today_start_end_datetime(self):
company = self.env.company
company = self.picking_types.company_id
tz = company.partner_id.tz or "UTC"
today = fields.Datetime.today()
today_start = fields.Datetime.start_of(today, "day")
Expand Down Expand Up @@ -1054,7 +1054,7 @@ def _create_lot_values(self, product, lot_name):
return {
"name": lot_name,
"product_id": product.id,
"company_id": self.env.company.id,
"company_id": self.picking_types.company_id.id,
"use_expiration_date": product.use_expiration_date,
}

Expand Down Expand Up @@ -1349,7 +1349,7 @@ def set_destination(
)
search = self._actions_for("search")

location = search.location_from_scan(location_name)
location = search.location_from_scan(location_name, company=picking.company_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

Suggested change
search = self._actions_for("search")
location = search.location_from_scan(location_name)
location = search.location_from_scan(location_name, company=picking.company_id)
search = self._actions_for("search").with_company(picking.company_id)
location = search.location_from_scan(location_name)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will change it i like your suggestion

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with_company cannot be called on a work component.

@simahawk How would you solve to provide the right company to the env of the component as it affects several search methods in shopfloor

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will change it i like your suggestion

I will give it a try tomorrow by extending shopfloor.search.action

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mt-software-de You could modify shopfloor base service with something like this to define with_company

    @property
    def company(self):
        if self._company is None:
            return self.env.company
        return self._company

    @contextmanager
    def with_company(self, company):
        try:
            self._company = company
            yield
        finally:
            self._company = None


    def _actions_for(self, usage, **kw):
        return get_actions_for(self, usage, company=self.company, **kw)

You would need to initialize in an init method _company = None in that base service

In the action, you could then retrieve the company with self.work.company instead of using self.env.company

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there was a new issue in the checkout scenario, i changed the approach.
Now the base of all scenarios are changed. base.shopfloor.process.
When _actions_for is called, it tries to set the company from self.work.menu.picking_type_ids.company,
this ensures that the env has the right company set.
Maybe it is possible to set already in __init__, but i didn't checked. The first tests on our side worked.

IMO. Its better to have the right company in the env already instead of passing it. Or using a new property.

cc @jbaudoux

if not location:
return self._response_for_set_destination(
picking, selected_line, message=self.msg_store.no_location_found()
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
freezegun
odoo_test_helper
odoo14-addon-shopfloor @ git+https://github.com/OCA/wms.git@refs/pull/1131/head#subdirectory=setup/shopfloor
Loading