diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 8afb332bc7d..1492143a7d0 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -492,7 +492,7 @@ class sale_order(osv.osv): if line.procurement_id: res.append(line.procurement_id.id) return res - + # if mode == 'finished': # returns True if all lines are done, False otherwise # if mode == 'canceled': @@ -504,9 +504,22 @@ class sale_order(osv.osv): notcanceled = False write_done_ids = [] write_cancel_ids = [] + stock_move_obj = self.pool.get('stock.move') + for order in self.browse(cr, uid, ids, context={}): - for line in order.order_line: - if (not line.procurement_id) or (line.procurement_id.state=='done'): + + #check for pending deliveries + pending_deliveries = False + + for line in order.order_line: + move_ids = stock_move_obj.search(cr, uid, [('sale_line_id','=', line.id)]) + for move in stock_move_obj.browse( cr, uid, move_ids ): + #if one of the related order lines is in state draft, auto or confirmed + #this order line is not yet delivered + if move.state in ('draft', 'auto', 'confirmed'): + pending_deliveries = True + + if ((not line.procurement_id) or (line.procurement_id.state=='done')) and not pending_deliveries: finished = True if line.state != 'done': write_done_ids.append(line.id) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 2a372d4eeed..039dfdd99fd 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1135,6 +1135,11 @@ class stock_move(osv.osv): if move.state in ('confirmed', 'waiting'): res = self.pool.get('stock.location')._product_reserve(cr, uid, [move.location_id.id], move.product_id.id, move.product_qty, {'uom': move.product_uom.id}) if res: + #_product_available_test depends on the next status for correct functioning + #the test does not work correctly if the same product occurs multiple times + #in the same order. This is e.g. the case when using the button 'split in two' of + #the stock outgoing form + self.write(cr, uid, move.id, {'state':'assigned'}) done.append(move.id) pickings[move.picking_id.id] = 1 r = res.pop(0)