From 1caa112b2059c1ebbbe214bd06d0d9c15e5ed2ee Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Wed, 17 Jul 2013 14:42:55 +0200 Subject: [PATCH] [WIP] search_suitable_rule should be responsible for taking route_ids into account or not bzr revid: jco@openerp.com-20130717124255-e3a9i0nh85z00895 --- addons/stock/procurement.py | 2 +- addons/stock_location/stock_location.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/addons/stock/procurement.py b/addons/stock/procurement.py index 41e88d9a68e..cdf11ebdd90 100644 --- a/addons/stock/procurement.py +++ b/addons/stock/procurement.py @@ -57,7 +57,7 @@ class procurement_order(osv.osv): def _find_suitable_rule(self, cr, uid, procurement, context=None): rule_id = super(procurement_order, self)._find_suitable_rule(cr, uid, procurement, context=context) if not rule_id: - rule_id = self._search_suitable_rule(cr, uid, procurement, [('action', '=', 'move'), ('location_id', '=', procurement.location_id.id)], context=context) + rule_id = self._search_suitable_rule(cr, uid, procurement, [('location_id', '=', procurement.location_id.id)], context=context) #action=move rule_id = rule_id and rule_id[0] or False return rule_id diff --git a/addons/stock_location/stock_location.py b/addons/stock_location/stock_location.py index df33a55bb2b..3f039d1c1b5 100644 --- a/addons/stock_location/stock_location.py +++ b/addons/stock_location/stock_location.py @@ -158,15 +158,22 @@ class procurement_order(osv.osv): }) return d + def _find_suitable_rule(self, cr, uid, procurement, context=None): + rule_id = super(procurement_order, self)._find_suitable_rule(cr, uid, procurement, context=context) + if not rule_id: + rule_id = self._search_suitable_rule(cr, uid, procurement, [('location_id', '=', procurement.location_id.id)], context=context) #action=move + rule_id = rule_id and rule_id[0] or False + return rule_id + def _search_suitable_rule(self, cr, uid, procurement, domain, context=None): '''we try to first find a rule among the ones defined on the procurement order group and if none is found, we try on the routes defined for the product, and finally we fallback on the default behavior''' route_ids = [x.id for x in procurement.route_ids] - res = super(procurement_order, self)._search_suitable_rule(cr, uid, procurement, domain + [('route_id', 'in', route_ids)], context=context) + res = self.pool.get('procurement.rule').search(cr, uid, domain + [('route_id', 'in', route_ids)], context=context) if not res: route_ids = [x.id for x in procurement.product_id.route_ids] - res = super(procurement_order, self)._search_suitable_rule(cr, uid, procurement, domain + [('route_id', 'in', route_ids)], context=context) + self.pool.get('procurement.rule').search(cr, uid, domain + [('route_id', 'in', route_ids)], context=context) if not res: - return super(procurement_order, self)._search_suitable_rule(cr, uid, procurement, domain, context=context) + self.pool.get('procurement.rule').search(cr, uid, domain, context=context) return res