diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 4f7f43f62ae6eb4bdd75cd8348996352a4cf334b..8f365343d41e33bb51a67f2e968aa77e3226ec59 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -715,31 +715,21 @@ class Picking(models.Model): @api.depends('state', 'move_lines', 'move_lines.state', 'move_lines.package_level_id', 'move_lines.move_line_ids.package_level_id') def _compute_move_without_package(self): for picking in self: - picking.move_ids_without_package = picking._get_move_ids_without_package() + move_ids_without_package = self.env['stock.move'] + if picking.picking_type_entire_packs == False: + move_ids_without_package = picking.move_lines + else: + for move in picking.move_lines: + if not move.package_level_id: + if move.state in ('assigned', 'done'): + if any(not ml.package_level_id for ml in move.move_line_ids): + move_ids_without_package |= move + else: + move_ids_without_package |= move + picking.move_ids_without_package = move_ids_without_package.filtered(lambda move: not move.scrap_ids) def _set_move_without_package(self): - new_mwp = self[0].move_ids_without_package - for picking in self: - old_mwp = picking._get_move_ids_without_package() - picking.move_lines = (picking.move_lines - old_mwp) | new_mwp - moves_to_unlink = old_mwp - new_mwp - if moves_to_unlink: - moves_to_unlink.unlink() - - def _get_move_ids_without_package(self): - self.ensure_one() - move_ids_without_package = self.env['stock.move'] - if not self.picking_type_entire_packs: - move_ids_without_package = self.move_lines - else: - for move in self.move_lines: - if not move.package_level_id: - if move.state in ('assigned', 'done'): - if any(not ml.package_level_id for ml in move.move_line_ids): - move_ids_without_package |= move - else: - move_ids_without_package |= move - return move_ids_without_package.filtered(lambda move: not move.scrap_ids) + self.move_lines |= self.move_ids_without_package def _check_move_lines_map_quant_package(self, package): """ This method checks that all product of the package (quant) are well present in the move_line_ids of the picking. """ diff --git a/addons/stock/tests/test_move2.py b/addons/stock/tests/test_move2.py index 24e6e2de6555dd31ba86678944a4a943b2a0ccad..e1380a8ec2885c76b8bf6870f9e49e86ce3d2326 100644 --- a/addons/stock/tests/test_move2.py +++ b/addons/stock/tests/test_move2.py @@ -1815,20 +1815,6 @@ class TestSinglePicking(TestStockCommon): back_order = self.env['stock.picking'].search([('backorder_id', '=', delivery_order.id)]) self.assertFalse(back_order, 'There should be no back order') - def test_unlink_move_1(self): - picking = Form(self.env['stock.picking']) - ptout = self.env['stock.picking.type'].browse(self.picking_type_out) - picking.picking_type_id = ptout - with picking.move_ids_without_package.new() as move: - move.product_id = self.productA - move.product_uom_qty = 10 - picking = picking.save() - - picking = Form(picking) - picking.move_ids_without_package.remove(0) - picking = picking.save() - self.assertEqual(len(picking.move_ids_without_package), 0) - def test_owner_1(self): """Make a receipt, set an owner and validate""" owner1 = self.env['res.partner'].create({'name': 'owner'})