From 508e5ed9dd603c38912dacd7774cfb420df58ee0 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 4 May 2017 16:49:03 +0200 Subject: [PATCH] [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 --- addons/stock/models/stock_move.py | 5 ++++- addons/stock_account/models/stock.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index c9a50f3f704..70c9fe55d14 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -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 diff --git a/addons/stock_account/models/stock.py b/addons/stock_account/models/stock.py index e5087c67814..074a0ab748d 100644 --- a/addons/stock_account/models/stock.py +++ b/addons/stock_account/models/stock.py @@ -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()