From 3bea85804abddce337e435b019b9a6677fa3e821 Mon Sep 17 00:00:00 2001 From: Enric Tobella Date: Thu, 15 Mar 2018 09:13:42 +0100 Subject: [PATCH] [FIX] stock_request: Add the option to select all the possible rules of a location, the rules of the parents are also allowed --- stock_request/models/stock_request.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/stock_request/models/stock_request.py b/stock_request/models/stock_request.py index 6099766f7..af8615424 100644 --- a/stock_request/models/stock_request.py +++ b/stock_request/models/stock_request.py @@ -177,6 +177,14 @@ class StockRequest(models.Model): request.product_id.uom_id._compute_quantity( open_qty, request.product_uom_id) + def get_parents(self): + location = self.location_id.sudo() + result = location + while location.location_id: + location = location.location_id + result |= location + return result + @api.constrains('product_id') def _check_product_uom(self): ''' Check if the UoM has the same category as the @@ -197,8 +205,9 @@ class StockRequest(models.Model): if self.warehouse_id: routes |= self.env['stock.location.route'].search( [('warehouse_ids', 'in', self.warehouse_id.ids)]) + parents = self.get_parents().ids routes = routes.filtered(lambda r: any( - p.location_id == self.location_id for p in r.pull_ids)) + p.location_id.id in parents for p in r.pull_ids)) return routes @api.onchange('warehouse_id')