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

This reverts commit 3431d7b1cd.
Due to recent changes in the orm, editing a draft move crashes. We
revert this commit while we find a proper fix.

closes odoo/odoo#37752

Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
Simon Lejeune
2019-10-02 06:56:43 +00:00
parent acde911e44
commit 61fa590e67
2 changed files with 13 additions and 37 deletions
+13 -23
View File
@@ -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. """
-14
View File
@@ -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'})