[FIX] stock_account: avco and unlock

Fixes #38313

closes odoo/odoo#38555

X-original-commit: 843c22fc14a138a6104c6ce8f26b928ef0337d18
Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
Simon Lejeune
2019-10-11 22:36:32 +00:00
committed by fw-bot
parent ededc5138d
commit 2124f1b930
2 changed files with 38 additions and 2 deletions
+2 -2
View File
@@ -303,15 +303,15 @@ class StockMove(models.Model):
for valued_move_line in valued_move_lines:
qty_done += valued_move_line.product_uom_id._compute_quantity(valued_move_line.qty_done, move.product_id.uom_id)
qty = forced_qty or qty_done
if float_is_zero(product_tot_qty_available, precision_rounding=rounding):
new_std_price = move._get_price_unit()
elif float_is_zero(product_tot_qty_available + move.product_qty, precision_rounding=rounding) or \
float_is_zero(product_tot_qty_available + qty_done, precision_rounding=rounding):
float_is_zero(product_tot_qty_available + qty, precision_rounding=rounding):
new_std_price = move._get_price_unit()
else:
# Get the standard price
amount_unit = std_price_update.get((move.company_id.id, move.product_id.id)) or move.product_id.with_context(force_company=move.company_id.id).standard_price
qty = forced_qty or qty_done
new_std_price = ((amount_unit * product_tot_qty_available) + (move._get_price_unit() * qty)) / (product_tot_qty_available + qty)
tmpl_dict[move.product_id.id] += qty_done
@@ -2342,6 +2342,42 @@ class TestStockValuation(SavepointCase):
self.assertAlmostEqual(self.product1.standard_price, 10.0)
def test_average_perpetual_8(self):
""" When a product has an available quantity of -5, edit an incoming shipment and increase
the received quantity by 5 units.
"""
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()
# deliver 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._action_done()
# increase the receipt to 15
move1.move_line_ids.qty_done = 15
def test_average_negative_1(self):
""" Test edit in the past. Receive 10, send 20, edit the second move to only send 10.
"""