=== modified file 'stock/wizard/stock_return_picking.py' --- stock/wizard/stock_return_picking.py 2013-09-09 15:25:01 +0000 +++ stock/wizard/stock_return_picking.py 2013-10-24 12:11:55 +0000 @@ -135,6 +135,28 @@ return_history[m.id] += (rec.product_qty * rec.product_uom.factor) return return_history + def _get_return_location_id(self, cr, uid, move, context=None): + """ + Return a location id where returned product are received which + shall not be an output location + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param move: the returned move + @return: a location_id + """ + warehouse_obj = self.pool.get('stock.warehouse') + + while move.move_history_ids2 != []: + move = move.move_history_ids2[0] + warehouse_ids = warehouse_obj.search(cr, uid, + [('lot_output_id', '=', move.location_id.id)], + context=context) + if warehouse_ids: + warehouse = warehouse_obj.browse(cr, uid, warehouse_ids[0], context=context) + return warehouse.lot_stock_id.id + return move.location_id.id + def create_returns(self, cr, uid, ids, context=None): """ Creates return picking. @@ -196,6 +218,10 @@ if returned_qty != new_qty: set_invoice_state_to_none = False + + + return_location_id = self._get_return_location_id(cr, uid, move, context=context) + if new_qty: returned_lines += 1 new_move=move_obj.copy(cr, uid, move.id, { @@ -204,7 +230,7 @@ 'picking_id': new_picking, 'state': 'draft', 'location_id': new_location, - 'location_dest_id': move.location_id.id, + 'location_dest_id': return_location_id, 'date': date_cur, }) move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]}, context=context)