From 0fc9e8fbcc2675ee009885be35e8a14cb63491b4 Mon Sep 17 00:00:00 2001 From: yhu-odoo Date: Tue, 16 Feb 2021 14:20:08 +0000 Subject: [PATCH] [IMP] stock: no extra moves when over consumption This commit is a revert of revert 561b3461a020021d911999cb41154f158b069a1d and 97ba860fd38c530d3f3678f676754862afad0f11. Previously we split moves when no picking, now we consider it unnecessary. Task 2446915 COM PR #66583 ENT PR odoo/enterprise#16554 --- addons/mrp/tests/test_order.py | 17 ++++++++--------- addons/stock/models/stock_move.py | 21 +-------------------- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index b84341fd69f..5e496310d47 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -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, diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index bcad795b6b3..ac9351b732f 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -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):