From c47dc928f6ec67f0e76c8b7907d7f62ae2452d89 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Tue, 5 Feb 2019 15:05:34 +0000 Subject: [PATCH] [FIX] stock: warehouse_selectable skip warehouse_ids Usecase to reproduce: - Create a route with a warehouse_ids - Uncheck warehouse_selectable on route - Create a picking that use the route It should fail since the route is not applicable. It happens because _search_rule only check for route with warehouse_ids but it do not check for warehouse_selectable. We can't fix _search_rule since stock_warehouse.py creates multi step delivery and reception routes without warehouse_selectable thus it would break existing configuration. Instead create an onchange on warehouse_selectable that remove warehouse_ids on route. partial backport of commit a35df8d37170790257876a54aa54f2c3ab596c44 closes odoo/odoo#30844 --- addons/stock/models/stock_location.py | 5 +++++ addons/stock/models/stock_warehouse.py | 1 + 2 files changed, 6 insertions(+) diff --git a/addons/stock/models/stock_location.py b/addons/stock/models/stock_location.py index bce2de0ecd2..b3903df88b7 100644 --- a/addons/stock/models/stock_location.py +++ b/addons/stock/models/stock_location.py @@ -170,6 +170,11 @@ class Route(models.Model): categ_ids = fields.Many2many('product.category', 'stock_location_route_categ', 'route_id', 'categ_id', 'Product Categories') warehouse_ids = fields.Many2many('stock.warehouse', 'stock_route_warehouse', 'route_id', 'warehouse_id', 'Warehouses') + @api.onchange('warehouse_selectable') + def _onchange_warehouse_selectable(self): + if not self.warehouse_selectable: + self.warehouse_ids = [] + def write(self, values): '''when a route is deactivated, deactivate also its pull and push rules''' res = super(Route, self).write(values) diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index 3394c3a1e7b..dc8766954de 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -467,6 +467,7 @@ class Warehouse(models.Model): 'name': self._format_routename(route_type=route_type), 'product_categ_selectable': True, 'product_selectable': False, + 'warehouse_selectable': True, 'company_id': self.company_id.id, 'sequence': 10, }