diff options
| author | William Henrotin <whe@odoo.com> | 2021-03-02 15:11:35 +0000 |
|---|---|---|
| committer | William Henrotin <whe@odoo.com> | 2021-03-02 17:18:13 +0000 |
| commit | b7d722df47bffb9fffc35842b4869b6a296c4ae3 (patch) | |
| tree | 182c916cf8d9578963555437b79776068d0f1542 | |
| parent | 6916981f56783de7008cd04d4e37e80166150ff7 (diff) | |
[FIX] stock_account: compute value in sudo
This commit makes the product's value computation in sudo mode in order
to be performed even by stock users.
closes odoo/odoo#67108
X-original-commit: a87c7fbad55d987b37a50e2b74b4dd9f9096a349
Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
| -rw-r--r-- | addons/stock_account/models/product.py | 4 | ||||
| -rw-r--r-- | addons/stock_account/tests/test_stockvaluation.py | 31 |
2 files changed, 33 insertions, 2 deletions
diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py index 901d393984c..667ea124a5e 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 13e0cd15c2b..e0b5332d2d7 100644 --- a/addons/stock_account/tests/test_stockvaluation.py +++ b/addons/stock_account/tests/test_stockvaluation.py @@ -2487,6 +2487,37 @@ class TestStockValuation(SavepointCase): # 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. """ |
