From d45fd02abd97ce31a018da4c34084c23d820d444 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Thu, 3 Apr 2014 17:57:35 +0200 Subject: [PATCH] [IMP] Push rules should try to find routes on warehouse first before searching anything bzr revid: jco@openerp.com-20140403155735-y357mj3gtp7j3x7i --- addons/purchase/purchase.py | 1 + addons/stock/product.py | 1 - addons/stock/stock.py | 16 ++++++++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index df516b20587..44401fa22f7 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -695,6 +695,7 @@ class purchase_order(osv.osv): 'procurement_id': False, 'origin': order.name, 'route_ids': order.picking_type_id.warehouse_id and [(6, 0, [x.id for x in order.picking_type_id.warehouse_id.route_ids])] or [], + 'warehouse_id':order.picking_type_id.warehouse_id.id, } diff_quantity = order_line.product_qty diff --git a/addons/stock/product.py b/addons/stock/product.py index 71402d363a4..d1b8691e0cc 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -136,7 +136,6 @@ class product_product(osv.osv): moves_in = dict(map(lambda x: (x['product_id'][0], x['product_qty']), moves_in)) moves_out = dict(map(lambda x: (x['product_id'][0], x['product_qty']), moves_out)) - res = {} for id in ids: res[id] = { diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 084d554799c..d0cdec8a33f 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1794,18 +1794,26 @@ class stock_move(osv.osv): # to receive goods without triggering the push rules again (which would duplicate chained operations) if not move.move_dest_id and not move.origin_returned_move_id: domain = [('location_from_id', '=', move.location_dest_id.id)] - if move.warehouse_id: - domain += ['|', ('warehouse_id', '=', move.warehouse_id.id), ('warehouse_id', '=', False)] + #priority goes to the route defined on the product and product category route_ids = [x.id for x in move.product_id.route_ids + move.product_id.categ_id.total_route_ids] rules = push_obj.search(cr, uid, domain + [('route_id', 'in', route_ids)], order='route_sequence, sequence', context=context) if not rules: - #but if there's no rule matching, we try without filtering on routes - rules = push_obj.search(cr, uid, domain, order='route_sequence, sequence', context=context) + route_ids = [] + if move.warehouse_id: + route_ids = [x.id for x in move.warehouse_id.route_ids] + elif move.picking_type_id and move.picking_type_id.warehouse_id: + route_ids = [x.id for x in move.picking_type_id.warehouse_id.route_ids] + if route_ids: + rules = push_obj.search(cr, uid, domain + [('route_id', 'in', route_ids)], order='route_sequence, sequence', context=context) + if not rules: + #but if there's no rule matching, we try without filtering on routes + rules = push_obj.search(cr, uid, domain, order='route_sequence, sequence', context=context) if rules: rule = push_obj.browse(cr, uid, rules[0], context=context) push_obj._apply(cr, uid, rule, move, context=context) return True + def _create_procurement(self, cr, uid, move, context=None): """ This will create a procurement order """