diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py index e76b8f48da6..2f362668367 100644 --- a/addons/stock_account/models/product.py +++ b/addons/stock_account/models/product.py @@ -93,8 +93,8 @@ class ProductTemplate(models.Model): class ProductProduct(models.Model): _inherit = 'product.product' - value_svl = fields.Float(compute='_compute_value_svl') - quantity_svl = fields.Float(compute='_compute_value_svl') + value_svl = fields.Float(compute='_compute_value_svl', compute_sudo=True) + quantity_svl = fields.Float(compute='_compute_value_svl', compute_sudo=True) stock_valuation_layer_ids = fields.One2many('stock.valuation.layer', 'product_id') valuation = fields.Selection(related="categ_id.property_valuation", readonly=True) cost_method = fields.Selection(related="categ_id.property_cost_method", readonly=True) diff --git a/addons/stock_account/tests/test_stockvaluation.py b/addons/stock_account/tests/test_stockvaluation.py index bda88914212..c8e28db0242 100644 --- a/addons/stock_account/tests/test_stockvaluation.py +++ b/addons/stock_account/tests/test_stockvaluation.py @@ -2487,6 +2487,37 @@ class TestStockValuation(TransactionCase): # increase the receipt to 15 move1.move_line_ids.qty_done = 15 + def test_average_stock_user(self): + """ deliver an average product as a stock user. """ + self.product1.categ_id.property_cost_method = 'average' + # receive 10 + move1 = self.env['stock.move'].create({ + 'name': 'IN 5@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': 10, + 'price_unit': 10, + }) + move1._action_confirm() + move1.quantity_done = 10 + move1._action_done() + + # sell 15 + move2 = self.env['stock.move'].create({ + 'name': 'Deliver 10 units', + 'location_id': self.stock_location.id, + 'location_dest_id': self.customer_location.id, + 'product_id': self.product1.id, + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 15.0, + }) + move2._action_confirm() + move2._action_assign() + move2.move_line_ids.qty_done = 15.0 + move2.with_user(self.inventory_user)._action_done() + def test_average_negative_1(self): """ Test edit in the past. Receive 10, send 20, edit the second move to only send 10. """