From 58316d1546420d72642a13d9648b323f4b1dfd59 Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Fri, 12 Jun 2020 15:01:53 +0000 Subject: [PATCH] [IMP] delivery, stock(_picking_batch): add "Put In Pack" button This commit sets up the logic and adds the button for "Put in Pack" action that already exists in stock.picking. Reuse/extension of logic from stock.picking reused where possible, including extension of pack wizard to handle products with different destination. Note that logic to handle "Delivery Packaging" wizard when "Delivery Methods" is active was purposely not extended to work correctly in batch pickings due to complexity of adding in a new module just to handle conflicting carrier_ids across pickings in the same batch. It is expected that this use case will not occur except in case of user error. Additionally, stock.picking implementation of 'put_in_pack' method has been renamed to 'action_put_in_pack' to have consistent naming (and support enterprise level code). Part of "1. Improve Batch Pickings" specification of overall barcode improvements task. Task: 1884520 Enterprise PR: odoo/enterprise#12086 Closes: odoo/odoo#55096 --- .../delivery/tests/test_packing_delivery.py | 2 +- .../wizard/choose_delivery_package.py | 2 +- .../wizard/choose_delivery_package_views.xml | 2 +- addons/stock/models/stock_picking.py | 21 +++++----- addons/stock/tests/test_move.py | 10 ++--- addons/stock/tests/test_packing.py | 14 +++---- addons/stock/tests/test_stock_flow.py | 2 +- addons/stock/views/stock_picking_views.xml | 6 +-- .../stock/wizard/stock_package_destination.py | 7 ++-- .../models/stock_picking_batch.py | 26 +++++++++++- .../tests/test_batch_picking.py | 40 +++++++++++++++++++ .../views/stock_picking_batch_views.xml | 1 + addons/stock_picking_batch/wizard/__init__.py | 1 + .../wizard/stock_package_destination.py | 25 ++++++++++++ 14 files changed, 125 insertions(+), 34 deletions(-) create mode 100644 addons/stock_picking_batch/wizard/stock_package_destination.py diff --git a/addons/delivery/tests/test_packing_delivery.py b/addons/delivery/tests/test_packing_delivery.py index c40cdb2d500..e4710c705e8 100644 --- a/addons/delivery/tests/test_packing_delivery.py +++ b/addons/delivery/tests/test_packing_delivery.py @@ -65,7 +65,7 @@ class TestPacking(TestPackingCommon): 'location_dest_id': self.customer_location.id }) picking_ship.action_confirm() - pack_action = picking_ship.put_in_pack() + pack_action = picking_ship.action_put_in_pack() pack_action_ctx = pack_action['context'] pack_action_model = pack_action['res_model'] diff --git a/addons/delivery/wizard/choose_delivery_package.py b/addons/delivery/wizard/choose_delivery_package.py index 1932b798c11..83026e5e3d6 100644 --- a/addons/delivery/wizard/choose_delivery_package.py +++ b/addons/delivery/wizard/choose_delivery_package.py @@ -46,7 +46,7 @@ class ChooseDeliveryPackage(models.TransientModel): } return {'warning': warning_mess} - def put_in_pack(self): + def action_put_in_pack(self): picking_move_lines = self.picking_id.move_line_ids if not self.picking_id.picking_type_id.show_reserved: picking_move_lines = self.picking_id.move_line_nosuggest_ids diff --git a/addons/delivery/wizard/choose_delivery_package_views.xml b/addons/delivery/wizard/choose_delivery_package_views.xml index 5f39d08d81a..5346ca84103 100644 --- a/addons/delivery/wizard/choose_delivery_package_views.xml +++ b/addons/delivery/wizard/choose_delivery_package_views.xml @@ -16,7 +16,7 @@ diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 9c266ce95c3..f76d0aa2ea9 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -1280,7 +1280,7 @@ class Picking(models.Model): else: return {} - def _put_in_pack(self, move_line_ids): + def _put_in_pack(self, move_line_ids, create_package_level=True): package = False for pick in self: move_lines_to_pack = self.env['stock.move.line'] @@ -1312,20 +1312,21 @@ class Picking(models.Model): ml.write(vals) new_move_line.write({'product_uom_qty': done_to_keep}) move_lines_to_pack |= new_move_line - package_level = self.env['stock.package_level'].create({ - 'package_id': package.id, - 'picking_id': pick.id, - 'location_id': False, - 'location_dest_id': move_line_ids.mapped('location_dest_id').id, - 'move_line_ids': [(6, 0, move_lines_to_pack.ids)], - 'company_id': pick.company_id.id, - }) + if create_package_level: + package_level = self.env['stock.package_level'].create({ + 'package_id': package.id, + 'picking_id': pick.id, + 'location_id': False, + 'location_dest_id': move_line_ids.mapped('location_dest_id').id, + 'move_line_ids': [(6, 0, move_lines_to_pack.ids)], + 'company_id': pick.company_id.id, + }) move_lines_to_pack.write({ 'result_package_id': package.id, }) return package - def put_in_pack(self): + def action_put_in_pack(self): self.ensure_one() if self.state not in ('done', 'cancel'): picking_move_lines = self.move_line_ids diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index 65dd48a1c75..97dc10346fb 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -4381,13 +4381,13 @@ class StockMove(SavepointCase): picking.action_assign() self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0) move1.quantity_done = 1 - picking.put_in_pack() + picking.action_put_in_pack() self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0) self.assertEqual(len(picking.move_line_ids), 2) unpacked_ml = picking.move_line_ids.filtered(lambda ml: not ml.result_package_id) self.assertEqual(unpacked_ml.product_qty, 1) unpacked_ml.qty_done = 1 - picking.put_in_pack() + picking.action_put_in_pack() self.assertEqual(len(picking.move_line_ids), 2) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0) picking.button_validate() @@ -4432,7 +4432,7 @@ class StockMove(SavepointCase): picking.action_assign() self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, self.stock_location), 0) - picking.put_in_pack() + picking.action_put_in_pack() self.assertEqual(len(picking.move_line_ids), 2) self.assertEqual(picking.move_line_ids[0].qty_done, 1, "Stock move line should have 1 quantity as a done quantity.") self.assertEqual(picking.move_line_ids[1].qty_done, 2, "Stock move line should have 2 quantity as a done quantity.") @@ -4482,9 +4482,9 @@ class StockMove(SavepointCase): self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, self.stock_location), 0) move1.quantity_done = 1 - picking.put_in_pack() + picking.action_put_in_pack() move2.quantity_done = 2 - picking.put_in_pack() + picking.action_put_in_pack() self.assertEqual(len(picking.move_line_ids), 2) line1_result_package = picking.move_line_ids[0].result_package_id line2_result_package = picking.move_line_ids[1].result_package_id diff --git a/addons/stock/tests/test_packing.py b/addons/stock/tests/test_packing.py index acdce51ef56..89ef70a0b1a 100644 --- a/addons/stock/tests/test_packing.py +++ b/addons/stock/tests/test_packing.py @@ -79,12 +79,12 @@ class TestPacking(TestPackingCommon): 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 - first_pack = pick_picking.put_in_pack() + first_pack = pick_picking.action_put_in_pack() self.assertEqual(len(pick_picking.package_level_ids), 1, 'Put some products in pack should create a package_level') self.assertEqual(pick_picking.package_level_ids[0].state, 'new', 'A new pack should be in state "new"') 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() + second_pack = pick_picking.action_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() @@ -235,7 +235,7 @@ class TestPacking(TestPackingCommon): picking.action_confirm() picking.action_assign() picking.move_line_ids.filtered(lambda ml: ml.product_id == self.productA).qty_done = 5.0 - picking.put_in_pack() + picking.action_put_in_pack() pack1 = self.env['stock.quant.package'].search([])[-1] picking.write({ 'move_line_ids': [(0, 0, { @@ -261,7 +261,7 @@ class TestPacking(TestPackingCommon): 'state': 'confirmed', })] }) - wizard_values = picking.put_in_pack() + wizard_values = picking.action_put_in_pack() wizard = self.env[(wizard_values.get('res_model'))].browse(wizard_values.get('res_id')) wizard.location_dest_id = shelf2_location.id wizard.action_done() @@ -424,7 +424,7 @@ class TestPacking(TestPackingCommon): with receipt_form.move_line_ids_without_package.edit(1) as move_line: move_line.qty_done = 1 receipt = receipt_form.save() - receipt.put_in_pack() + receipt.action_put_in_pack() receipt.button_validate() receipt_package = receipt.package_level_ids_details[0] @@ -563,7 +563,7 @@ class TestPacking(TestPackingCommon): with receipt_form.move_line_ids_without_package.edit(1) as move_line: move_line.qty_done = 1 receipt = receipt_form.save() - receipt.put_in_pack() + receipt.action_put_in_pack() receipt.button_validate() receipt_package = receipt.package_level_ids_details[0] @@ -665,4 +665,4 @@ class TestPacking(TestPackingCommon): pick_picking.action_assign() pick_picking.move_line_ids.qty_done = 3 - first_pack = pick_picking.put_in_pack() + first_pack = pick_picking.action_put_in_pack() diff --git a/addons/stock/tests/test_stock_flow.py b/addons/stock/tests/test_stock_flow.py index e5e301d723b..58bd6a3d16f 100644 --- a/addons/stock/tests/test_stock_flow.py +++ b/addons/stock/tests/test_stock_flow.py @@ -1328,7 +1328,7 @@ class TestStockFlow(TestStockCommon): # Set the quantity done on the pack operation move_in.move_line_ids.qty_done = 3.0 # Put in a pack - picking_in.put_in_pack() + picking_in.action_put_in_pack() # Get the new package picking_in_package = move_in.move_line_ids.result_package_id # Validate picking diff --git a/addons/stock/views/stock_picking_views.xml b/addons/stock/views/stock_picking_views.xml index 83100224c6e..b04462e3dfd 100644 --- a/addons/stock/views/stock_picking_views.xml +++ b/addons/stock/views/stock_picking_views.xml @@ -333,7 +333,7 @@ -