From 7076a86addb2e37dfa9d454864c73dca3a2a1b7c Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Mon, 27 Jan 2020 15:07:30 +0000 Subject: [PATCH] [IMP] stock: _get_rule allows to specify route_ids _search_rule on procurements search in a specific way in this order: - First: route passed in the procurement values - Second: route on product/product category - Third: route on warehouse - Fourth: remaining route. However _get_rule doesn't allow to simulate the first usecase with the route on procurement. This commit add the functionality. (Usefull for replenishment report where a route_id could be set on an orderpoint) Task: 2161378 --- addons/stock/models/product.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index 4158b86d84a..a95fe0bb8d2 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -518,16 +518,19 @@ class Product(models.Model): }) return super().write(values) - def _get_rules_from_location(self, location, seen_rules=False): + def _get_rules_from_location(self, location, route_ids=False, seen_rules=False): if not seen_rules: seen_rules = self.env['stock.rule'] - rule = self.env['procurement.group']._get_rule(self, location, {'warehouse_id': location.get_warehouse()}) + rule = self.env['procurement.group']._get_rule(self, location, { + 'route_ids': route_ids, + 'warehouse_id': location.get_warehouse() + }) if not rule: return seen_rules if rule.procure_method == 'make_to_stock' or rule.action not in ('pull_push', 'pull'): return seen_rules | rule else: - return self._get_rules_from_location(rule.location_src_id, seen_rules | rule) + return self._get_rules_from_location(rule.location_src_id, seen_rules=seen_rules | rule) class ProductTemplate(models.Model):