diff --git a/project_material/init_hook.py b/project_material/init_hook.py index 7d274cdd..3881ce8f 100644 --- a/project_material/init_hook.py +++ b/project_material/init_hook.py @@ -12,9 +12,6 @@ def post_init_hook(cr, registry): def _setup_warehouses_consumption_routes(env): warehouses = env["stock.warehouse"].search([]) for warehouse in warehouses: - location_id = env["ir.property"].with_company( - warehouse.company_id.id)._get( - "property_stock_production", "product.template") - warehouse.consu_location_id = location_id.id + warehouse.consu_location_id = warehouse._get_consu_location_id() warehouse._create_or_update_consumption_picking_types() warehouse._create_or_update_consumption_route() diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index 413d608a..46a1a01c 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -50,6 +50,8 @@ def create(self, vals): Use sudo to prevent errors related to access rights. """ warehouse = super().create(vals) + + warehouse.consu_location_id = warehouse._get_consu_location_id() warehouse.sudo()._create_consumption_picking_types() warehouse.sudo()._create_consumption_route() warehouse.sudo()._create_consumption_mto_pull() @@ -63,10 +65,18 @@ def write(self, vals): super().write(vals) if "consu_steps" in vals: for warehouse in self: + warehouse.consu_location_id = warehouse._get_consu_location_id() warehouse.sudo()._create_or_update_consumption_picking_types() warehouse.sudo()._create_or_update_consumption_route() warehouse.sudo()._create_or_update_consumption_mto_pull() return True + + @api.model + def _get_consu_location_id(self): + location_id = self.env["ir.property"].with_company( + self.company_id.id)._get( + "property_stock_production","product.template").id + return location_id def _create_or_update_consumption_picking_types(self): self = self.with_company(self.company_id)