[FIX] purchase: set the unit price to zero if requested in the purchase order

If a purchase order is created with free goods (e.g. 5 units offered if 100 are purchased),
the price_unit of stock.move and the cost of stock.quant were set to the product cost price
instead of zero. This would lead to inconsistencies in the 'Current Inventory Valuation'.

opw: 630593
This commit is contained in:
Nicolas Martinelli 2015-03-23 15:45:33 +01:00 committed by Josse Colpaert
parent 020caa17e4
commit 34c891a426
1 changed files with 14 additions and 0 deletions

View File

@ -31,6 +31,13 @@ class stock_move(osv.osv):
readonly=True),
}
def get_price_unit(self, cr, uid, move, context=None):
""" Returns the unit price to store on the quant """
if move.purchase_line_id:
return move.price_unit
return super(stock_move, self).get_price_unit(cr, uid, move, context=context)
def write(self, cr, uid, ids, vals, context=None):
if isinstance(ids, (int, long)):
ids = [ids]
@ -117,6 +124,13 @@ class stock_move(osv.osv):
"""
Attribute price to move, important in inter-company moves or receipts with only one partner
"""
# The method attribute_price of the parent class sets the price to the standard product
# price if move.price_unit is zero. We don't want this behavior in the case of a purchase
# order since we can purchase goods which are free of charge (e.g. 5 units offered if 100
# are purchased).
if move.purchase_line_id:
return
code = self.get_code_from_locs(cr, uid, move, context=context)
if not move.purchase_line_id and code == 'incoming' and not move.price_unit:
partner = move.picking_id and move.picking_id.partner_id or False