[FIX] stock: remove move 'without package' properly

on a picking, move_ids_without_package is a subset of move_lines.
The inverse function on move_ids_without_package only work well when we
add a move.

This commit improves the inverse function to take deletion into account

closes odoo/odoo#36558

Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
William
2019-09-20 14:01:19 +00:00
committed by Simon Lejeune
parent 7807bc854e
commit 3431d7b1cd
2 changed files with 37 additions and 13 deletions
+23 -13
View File
@@ -645,21 +645,31 @@ 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:
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)
picking.move_ids_without_package = picking._get_move_ids_without_package()
def _set_move_without_package(self):
self.move_lines |= self.move_ids_without_package
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)
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. """
+14
View File
@@ -1837,6 +1837,20 @@ 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)
class TestStockUOM(TestStockCommon):
def setUp(self):