[IMP] stock: no extra moves when over consumption
This commit is a revert of revert 561b3461a0
and 97ba860fd38c530d3f3678f676754862afad0f11.
Previously we split moves when no picking, now we consider it
unnecessary.
Task 2446915
COM PR #66583
ENT PR odoo/enterprise#16554
This commit is contained in:
@@ -149,11 +149,10 @@ class TestMrpOrder(TestMrpCommon):
|
||||
# check sub product availability state is assigned
|
||||
self.assertEqual(production_2.reservation_state, 'assigned', 'Production order should be availability for assigned state')
|
||||
|
||||
def test_split_move_line(self):
|
||||
""" Consume more component quantity than the initial demand.
|
||||
It should create extra move and share the quantity between the two stock
|
||||
moves """
|
||||
mo, bom, p_final, p1, p2 = self.generate_mo(qty_base_1=10, qty_final=1, qty_base_2=1)
|
||||
def test_over_consumption(self):
|
||||
""" Consume more component quantity than the initial demand. No split on moves.
|
||||
"""
|
||||
mo, _bom, _p_final, _p1, _p2 = self.generate_mo(qty_base_1=10, qty_final=1, qty_base_2=1)
|
||||
mo.action_assign()
|
||||
# check is_quantity_done_editable
|
||||
mo_form = Form(mo)
|
||||
@@ -175,10 +174,10 @@ class TestMrpOrder(TestMrpCommon):
|
||||
self.assertEqual(mo.move_raw_ids[0].quantity_done, 2)
|
||||
self.assertEqual(mo.move_raw_ids[1].quantity_done, 11)
|
||||
mo.button_mark_done()
|
||||
self.assertEqual(len(mo.move_raw_ids), 4)
|
||||
self.assertEqual(len(mo.move_raw_ids.mapped('move_line_ids')), 4)
|
||||
self.assertEqual(mo.move_raw_ids.mapped('quantity_done'), [1, 10, 1, 1])
|
||||
self.assertEqual(mo.move_raw_ids.mapped('move_line_ids.qty_done'), [1, 10, 1, 1])
|
||||
self.assertEqual(len(mo.move_raw_ids), 2)
|
||||
self.assertEqual(len(mo.move_raw_ids.mapped('move_line_ids')), 2)
|
||||
self.assertEqual(mo.move_raw_ids.mapped('quantity_done'), [2, 11])
|
||||
self.assertEqual(mo.move_raw_ids.mapped('move_line_ids.qty_done'), [2, 11])
|
||||
|
||||
def test_update_quantity_1(self):
|
||||
""" Build 5 final products with different consumed lots,
|
||||
|
||||
@@ -1489,30 +1489,11 @@ class StockMove(models.Model):
|
||||
|
||||
merge_into_self = all(self[field] == extra_move[field] for field in self._prepare_merge_moves_distinct_fields())
|
||||
|
||||
if merge_into_self and extra_move.picking_id:
|
||||
if merge_into_self:
|
||||
extra_move = extra_move._action_confirm(merge_into=self)
|
||||
return extra_move
|
||||
else:
|
||||
extra_move = extra_move._action_confirm()
|
||||
|
||||
# link it to some move lines. We don't need to do it for move since they should be merged.
|
||||
if not merge_into_self or not extra_move.picking_id:
|
||||
for move_line in self.move_line_ids.filtered(lambda ml: ml.qty_done):
|
||||
if float_compare(move_line.qty_done, extra_move_quantity, precision_rounding=rounding) <= 0:
|
||||
# move this move line to our extra move
|
||||
move_line.move_id = extra_move.id
|
||||
extra_move_quantity -= move_line.qty_done
|
||||
else:
|
||||
# split this move line and assign the new part to our extra move
|
||||
quantity_split = float_round(
|
||||
move_line.qty_done - extra_move_quantity,
|
||||
precision_rounding=self.product_uom.rounding,
|
||||
rounding_method='UP')
|
||||
move_line.qty_done = quantity_split
|
||||
move_line.copy(default={'move_id': extra_move.id, 'qty_done': extra_move_quantity, 'product_uom_qty': 0})
|
||||
extra_move_quantity -= extra_move_quantity
|
||||
if extra_move_quantity == 0.0:
|
||||
break
|
||||
return extra_move | self
|
||||
|
||||
def _action_done(self, cancel_backorder=False):
|
||||
|
||||
Reference in New Issue
Block a user