diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 0b436f0dc91..09f047929c4 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -709,6 +709,7 @@ class sale_order(osv.osv): #'state': 'waiting', 'note': line.notes, 'company_id': order.company_id.id, + 'price_unit': line.product_id.standard_price or 0.0 }) if line.product_id: diff --git a/addons/stock/stock.py b/addons/stock/stock.py index d478ab39c9c..f6e4d1f08ff 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1140,6 +1140,19 @@ class stock_picking(osv.osv): move_obj.unlink(cr, uid, ids2, ctx) return super(stock_picking, self).unlink(cr, uid, ids, context=context) + + def get_current_cost_price(self, cr, uid, ids, pick, move, product_price, context=None): + """@return: Return Current cost price""" + if context is None: + context = {} + price_unit = 0.0 + if (pick.type == 'in') and (move.product_id.cost_method == 'average'): + price_unit = product_price + elif move.price_unit == 0: + price_unit = move.product_id.standard_price + else: + price_unit = move.price_unit + return price_unit # FIXME: needs refactoring, this code is partially duplicated in stock_move.do_partial()! def do_partial(self, cr, uid, ids, partial_datas, context=None): @@ -1217,7 +1230,6 @@ class stock_picking(osv.osv): {'price_unit': product_price, 'price_currency_id': product_currency}) - for move in too_few: product_qty = move_product_qty[move.id] @@ -1229,35 +1241,45 @@ class stock_picking(osv.osv): 'state':'draft', }) if product_qty != 0: + price_unit = self.get_current_cost_price(cr, uid, ids, pick, move, product_price, context=context) defaults = { 'product_qty' : product_qty, 'product_uos_qty': product_qty, #TODO: put correct uos_qty 'picking_id' : new_picking, 'state': 'assigned', 'move_dest_id': False, - 'price_unit': move.price_unit, + 'price_unit': price_unit or 0.0 } prodlot_id = prodlot_ids[move.id] if prodlot_id: defaults.update(prodlot_id=prodlot_id) move_obj.copy(cr, uid, move.id, defaults) - + if (pick.type == 'in') and (move.product_id.cost_method == 'average'): + new_price_unit = move.product_id.standard_price + else: + new_price_unit = price_unit move_obj.write(cr, uid, [move.id], { 'product_qty' : move.product_qty - product_qty, 'product_uos_qty':move.product_qty - product_qty, #TODO: put correct uos_qty + 'price_unit': new_price_unit or 0.0 }) if new_picking: move_obj.write(cr, uid, [c.id for c in complete], {'picking_id': new_picking}) for move in complete: + price_unit = self.get_current_cost_price(cr, uid, ids, pick, move, product_price, context=context) + defaults = {'price_unit': price_unit or 0.0} if prodlot_ids.get(move.id): - move_obj.write(cr, uid, [move.id], {'prodlot_id': prodlot_ids[move.id]}) + defaults.update({'prodlot_id': prodlot_ids[move.id]}) + move_obj.write(cr, uid, [move.id], defaults) for move in too_many: + price_unit = self.get_current_cost_price(cr, uid, ids, pick, move, product_price, context=context) product_qty = move_product_qty[move.id] defaults = { 'product_qty' : product_qty, 'product_uos_qty': product_qty, #TODO: put correct uos_qty + 'price_unit': price_unit or 0.0 } prodlot_id = prodlot_ids.get(move.id) if prodlot_ids.get(move.id): @@ -2489,7 +2511,7 @@ class stock_move(osv.osv): for move in complete: if prodlot_ids.get(move.id): - self.write(cr, uid, [move.id],{'prodlot_id': prodlot_ids.get(move.id)}) + self.write(cr, uid, [move.id],{'prodlot_id': prodlot_ids.get(move.id), 'price_unit': move.product_id.standard_price}) self.action_done(cr, uid, [move.id], context=context) if move.picking_id.id : # TOCHECK : Done picking if all moves are done diff --git a/addons/stock/wizard/stock_return_picking.py b/addons/stock/wizard/stock_return_picking.py index b7c8aa28354..6b0ed010426 100644 --- a/addons/stock/wizard/stock_return_picking.py +++ b/addons/stock/wizard/stock_return_picking.py @@ -33,6 +33,7 @@ class stock_return_picking_memory(osv.osv_memory): 'quantity' : fields.float("Quantity", required=True), 'wizard_id' : fields.many2one('stock.return.picking', string="Wizard"), 'move_id' : fields.many2one('stock.move', "Move"), + 'price_unit' : fields.float('Cost Price', digits=(16,2), help="Historical cost price of product") } stock_return_picking_memory() @@ -73,7 +74,7 @@ class stock_return_picking(osv.osv_memory): for line in pick.move_lines: qty = line.product_qty - return_history[line.id] if qty > 0: - result1.append({'product_id': line.product_id.id, 'quantity': qty,'move_id':line.id}) + result1.append({'product_id': line.product_id.id, 'quantity': qty,'move_id':line.id, 'price_unit': line.price_unit}) if 'product_return_moves' in fields: res.update({'product_return_moves': result1}) return res @@ -180,9 +181,10 @@ class stock_return_picking(osv.osv_memory): 'product_qty': new_qty, 'product_uos_qty': uom_obj._compute_qty(cr, uid, move.product_uom.id, new_qty, move.product_uos.id), - 'picking_id':new_picking, 'state':'draft', - 'location_id':new_location, 'location_dest_id':move.location_id.id, - 'date':date_cur,}) + 'picking_id': new_picking, 'state': 'draft', + 'location_id': new_location, 'location_dest_id': move.location_id.id, + 'date': date_cur, + 'price_unit': move.price_unit}) move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]}) if not returned_lines: raise osv.except_osv(_('Warning !'), _("Please specify at least one non-zero quantity!")) diff --git a/addons/stock/wizard/stock_return_picking_view.xml b/addons/stock/wizard/stock_return_picking_view.xml index 51431eeee45..876dd3373da 100644 --- a/addons/stock/wizard/stock_return_picking_view.xml +++ b/addons/stock/wizard/stock_return_picking_view.xml @@ -18,7 +18,7 @@ - + @@ -31,6 +31,7 @@
+