From 9d87cdf8ef000c0b9036c13d5c817c360f646f3e Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 14 Feb 2014 10:40:16 +0100 Subject: [PATCH] [IMP] Change order in recompute remaining quantities bzr revid: jco@openerp.com-20140214094016-j4wg2yvq114jt7ye --- addons/stock/stock.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 3d0fabad0ff..85a84f18a81 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -3420,7 +3420,7 @@ class stock_pack_operation(osv.osv): def recompute_rem_qty_from_operation(self, cr, uid, op_ids, context=None): def _create_link_for_product(product_id, qty): qty_to_assign = qty - for move in op.picking_id.move_lines: + for move in sorted_moves: if move.product_id.id == product_id and move.state not in ['done', 'cancel']: qty_on_link = min(move.remaining_qty, qty_to_assign) link_obj.create(cr, uid, {'move_id': move.id, 'operation_id': op.id, 'qty': qty_on_link}, context=context) @@ -3432,6 +3432,11 @@ class stock_pack_operation(osv.osv): link_obj = self.pool.get('stock.move.operation.link') uom_obj = self.pool.get('product.uom') package_obj = self.pool.get('stock.quant.package') + if op_ids: + #Calculate order of moves + ops = self.browse(cr, uid, op_ids[0], context=context) + sorted_moves = ops.picking_id.move_lines + sorted_moves.sort(key = lambda x: x.product_qty - x.reserved_availability) for op in self.browse(cr, uid, op_ids, context=context): to_unlink_ids = [x.id for x in op.linked_move_operation_ids] if to_unlink_ids: