[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#67118 X-original-commit: a87c7fbad55d987b37a50e2b74b4dd9f9096a349 Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user