[FIX] stock: PO line with unit_price = 0 and cost_method = 'real' or 'average'
Let's consider the stockable product P with an internal category set with cost_method = 'real' and 'average'. When creating a PO with P and a unit_price=0, after delivering the product, the cost transfered to the stock valuation account was equal to the product cost multplied by the product quantity instead of the unit_price set on the PO multiplied by the quantity. PS: The quant is created with the stock.move in _quant_create_from_move and the unit_price set on the stock.move is taken with function get_price_unit. opw:740865
This commit is contained in:
@@ -498,9 +498,12 @@ class StockMove(models.Model):
|
||||
self._push_apply()
|
||||
return self
|
||||
|
||||
def _set_default_price_moves(self):
|
||||
return self.filtered(lambda move: not move.price_unit)
|
||||
|
||||
def set_default_price_unit_from_product(self):
|
||||
""" Set price to move, important in inter-company moves or receipts with only one partner """
|
||||
for move in self.filtered(lambda move: not move.price_unit):
|
||||
for move in self._set_default_price_moves():
|
||||
move.write({'price_unit': move.product_id.standard_price})
|
||||
attribute_price = set_default_price_unit_from_product
|
||||
|
||||
|
||||
@@ -173,6 +173,12 @@ class StockQuant(models.Model):
|
||||
class StockMove(models.Model):
|
||||
_inherit = "stock.move"
|
||||
|
||||
def _set_default_price_moves(self):
|
||||
# When the cost method is in real or average price, the price can be set to 0.0 on the PO
|
||||
# So the price doesn't have to be updated
|
||||
moves = super(StockMove, self)._set_default_price_moves()
|
||||
return moves.filtered(lambda m: not m.product_id.cost_method in ('real', 'average'))
|
||||
|
||||
@api.multi
|
||||
def action_done(self):
|
||||
self.product_price_update_before_done()
|
||||
|
||||
Reference in New Issue
Block a user