diff --git a/addons/stock/models/stock_package_level.py b/addons/stock/models/stock_package_level.py index a4d0c5be010..b6c7fb5a098 100644 --- a/addons/stock/models/stock_package_level.py +++ b/addons/stock/models/stock_package_level.py @@ -27,7 +27,7 @@ class StockPackageLevel(models.Model): ],string='State', compute='_compute_state') is_fresh_package = fields.Boolean(compute='_compute_fresh_pack') - picking_source_location = fields.Many2one('stock.location', related='picking_id.location_id', readonly=False) + picking_type_code = fields.Selection(related='picking_id.picking_type_code') show_lots_m2o = fields.Boolean(compute='_compute_show_lot') show_lots_text = fields.Boolean(compute='_compute_show_lot') @@ -182,3 +182,20 @@ class StockPackageLevel(models.Model): pl.location_id = pl.move_line_ids[0].location_id else: pl.location_id = pl.picking_id.location_id + + def action_show_package_details(self): + self.ensure_one() + view = self.env.ref('stock.package_level_form_view') + + return { + 'name': _('Package Content'), + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'stock.package_level', + 'views': [(view.id, 'form')], + 'view_id': view.id, + 'target': 'new', + 'res_id': self.id, + 'flags': {'mode': 'readonly'}, + } diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 93187e523bc..7099268444c 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -239,7 +239,7 @@ class Picking(models.Model): readonly=True, required=True, states={'draft': [('readonly', False)]}) move_lines = fields.One2many('stock.move', 'picking_id', string="Stock Moves", copy=True) - move_ids_without_package = fields.One2many('stock.move', 'picking_id', string="Stock moves not in package", domain=['|',('package_level_id', '=', False), ('picking_type_entire_packs', '=', False)]) + move_ids_without_package = fields.One2many('stock.move', 'picking_id', string="Stock moves not in package", compute='_compute_move_without_package', inverse='_set_move_without_package') has_scrap_move = fields.Boolean( 'Has Scrap Moves', compute='_has_scrap_move') picking_type_id = fields.Many2one( @@ -626,6 +626,25 @@ class Picking(models.Model): self.write({'date_done': fields.Datetime.now()}) return True + @api.depends('state', 'move_lines', 'move_lines.state', 'move_lines.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 + self.move_ids_without_package = move_ids_without_package + + def _set_move_without_package(self): + 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. """ all_in = True diff --git a/addons/stock/tests/test_packing.py b/addons/stock/tests/test_packing.py index 9c711acd3e7..fcda966d04a 100644 --- a/addons/stock/tests/test_packing.py +++ b/addons/stock/tests/test_packing.py @@ -63,7 +63,11 @@ class TestPacking(TransactionCase): packing_picking = pack_move_a.picking_id shipping_picking = ship_move_a.picking_id + pick_picking.picking_type_entire_packs = True + packing_picking.picking_type_entire_packs = True + shipping_picking.picking_type_entire_packs = True pick_picking.action_assign() + self.assertEqual(len(pick_picking.move_ids_without_package), 2) pick_picking.move_line_ids.filtered(lambda ml: ml.product_id == self.productA).qty_done = 1.0 pick_picking.move_line_ids.filtered(lambda ml: ml.product_id == self.productB).qty_done = 2.0 @@ -73,7 +77,10 @@ class TestPacking(TransactionCase): pick_picking.move_line_ids.filtered(lambda ml: ml.product_id == self.productA and ml.qty_done == 0.0).qty_done = 4.0 pick_picking.move_line_ids.filtered(lambda ml: ml.product_id == self.productB and ml.qty_done == 0.0).qty_done = 3.0 second_pack = pick_picking.put_in_pack() + self.assertEqual(len(pick_picking.move_ids_without_package), 0) + self.assertEqual(len(packing_picking.move_ids_without_package), 2) pick_picking.button_validate() + self.assertEqual(len(packing_picking.move_ids_without_package), 0) self.assertEqual(len(first_pack.quant_ids), 2) self.assertEqual(len(second_pack.quant_ids), 2) packing_picking.action_assign() @@ -91,6 +98,7 @@ class TestPacking(TransactionCase): 'location_dest_id': self.stock_location.id, 'state': 'draft', }) + picking.picking_type_entire_packs = True package_level = self.env['stock.package_level'].create({ 'package_id': pack.id, 'picking_id': picking.id, @@ -99,6 +107,7 @@ class TestPacking(TransactionCase): self.assertEquals(package_level.state, 'draft', 'The package_level should be in draft as it has no moves, move lines and is not confirmed') picking.action_confirm() + self.assertEqual(len(picking.move_ids_without_package), 0) self.assertEqual(len(picking.move_lines), 1, 'One move should be created when the package_level has been confirmed') self.assertEquals(len(package_level.move_ids), 1, diff --git a/addons/stock/views/stock_package_level_views.xml b/addons/stock/views/stock_package_level_views.xml index ed7692b7fc8..30ed9f999a8 100644 --- a/addons/stock/views/stock_package_level_views.xml +++ b/addons/stock/views/stock_package_level_views.xml @@ -4,19 +4,19 @@ Package Level stock.package_level -
+
- + - - + + @@ -57,6 +57,7 @@ +