From 1c912767d148d22ff68c439dd84fa32df16269eb Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 12 Mar 2019 13:48:45 +0000 Subject: [PATCH] [FIX] stock_account: dropship & AVCO - Activate: 'Order-Specific Routes' and 'Dropshipping' - Create a stockable product in AVCO + AUTO - Purchase the product at $10 and validate the receipt => One product @ $10 in stock - Sell the product via dropshipping - A PO is generated, change unit price to $20, validate - Validate the picking The product in stock has now a cost of $15, i.e. the dropship impacted the cost of the product. Now if the product in stock is sold, the product will go out at a cost of $15. This will lead to a wrong accounting valuation (0 product in stock with -$5 in stock). opw-1922289 opw-1935272 opw-1937672 closes odoo/odoo#31786 Signed-off-by: Nicolas Martinelli (nim) --- addons/stock_account/models/stock.py | 2 +- .../tests/test_stockvaluation.py | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/addons/stock_account/models/stock.py b/addons/stock_account/models/stock.py index 1f337e7de22..6515309e9eb 100644 --- a/addons/stock_account/models/stock.py +++ b/addons/stock_account/models/stock.py @@ -377,7 +377,7 @@ class StockMove(models.Model): tmpl_dict = defaultdict(lambda: 0.0) # adapt standard price on incomming moves if the product cost_method is 'average' std_price_update = {} - for move in self.filtered(lambda move: move.location_id.usage in ('supplier', 'production') and move.product_id.cost_method == 'average'): + for move in self.filtered(lambda move: move._is_in() and move.product_id.cost_method == 'average'): product_tot_qty_available = move.product_id.qty_available + tmpl_dict[move.product_id.id] rounding = move.product_id.uom_id.rounding diff --git a/addons/stock_account/tests/test_stockvaluation.py b/addons/stock_account/tests/test_stockvaluation.py index aa06fabd1e5..50a2096ea24 100644 --- a/addons/stock_account/tests/test_stockvaluation.py +++ b/addons/stock_account/tests/test_stockvaluation.py @@ -2628,6 +2628,57 @@ class TestStockValuation(TransactionCase): self.assertAlmostEqual(self.product1.standard_price, 14.0) + def test_average_perpetual_8(self): + """ Receive 1@10, then dropship 1@20, finally return the dropship. Dropship should not + impact the price. + """ + self.product1.product_tmpl_id.cost_method = 'average' + + move1 = self.env['stock.move'].create({ + 'name': 'IN 1@10', + 'location_id': self.supplier_location.id, + 'location_dest_id': self.stock_location.id, + 'product_id': self.product1.id, + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 1, + 'price_unit': 10, + }) + move1._action_confirm() + move1.quantity_done = 1 + move1._action_done() + + self.assertAlmostEqual(self.product1.standard_price, 10) + + move2 = self.env['stock.move'].create({ + 'name': 'IN 1@20', + 'location_id': self.supplier_location.id, + 'location_dest_id': self.customer_location.id, + 'product_id': self.product1.id, + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 1, + 'price_unit': 20, + }) + move2._action_confirm() + move2.quantity_done = 1 + move2._action_done() + + self.assertAlmostEqual(self.product1.standard_price, 10.0) + + move3 = self.env['stock.move'].create({ + 'name': 'IN 1@20', + 'location_id': self.customer_location.id, + 'location_dest_id': self.supplier_location.id, + 'product_id': self.product1.id, + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 1, + 'price_unit': 20, + }) + move3._action_confirm() + move3.quantity_done = 1 + move3._action_done() + + self.assertAlmostEqual(self.product1.standard_price, 10.0) + def test_average_negative_1(self): """ Test edit in the past. Receive 10, send 20, edit the second move to only send 10. """