From bf53107c1ad51e4e61fbf8dfc4aafb17c83c3737 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Fri, 20 Sep 2024 16:44:01 +0200 Subject: [PATCH] [IMP] shopfloor_packing: Move data retrieval to data action + enable tests --- shopfloor_packing/actions/data.py | 18 ++++++++++++++++++ shopfloor_packing/services/cluster_picking.py | 15 +-------------- shopfloor_packing/tests/__init__.py | 4 ++-- .../tests/test_cluster_picking_pick_pack.py | 15 +++++++++++---- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/shopfloor_packing/actions/data.py b/shopfloor_packing/actions/data.py index e8d036e7c9..dc36ffabb7 100644 --- a/shopfloor_packing/actions/data.py +++ b/shopfloor_packing/actions/data.py @@ -12,3 +12,21 @@ def _package_parser(self): res = super()._package_parser res.append("is_internal") return res + + def _data_for_packing_info(self, picking): + """Return the packing information + + Intended to be extended. + """ + # TODO: This could be avoided if included in the picking parser. + return "" + + def select_package(self, picking, lines): + return { + "selected_move_lines": self.move_lines(lines.sorted()), + "picking": self.picking(picking), + "packing_info": self._data_for_packing_info(picking), + # "no_package_enabled": not self.options.get("checkout__disable_no_package"), + # Used by inheriting module + "package_allowed": True, + } diff --git a/shopfloor_packing/services/cluster_picking.py b/shopfloor_packing/services/cluster_picking.py index 8acde6aeb5..c32b2d131d 100644 --- a/shopfloor_packing/services/cluster_picking.py +++ b/shopfloor_packing/services/cluster_picking.py @@ -114,9 +114,6 @@ def scan_package_action(self, picking_id, selected_line_ids, barcode): # Call the specific put in pack with package type filled in return self._put_in_pack(self, picking, package_type_id=package_type_id) - def _data_for_move_lines(self, lines, **kw): - return self.data.move_lines(lines, **kw) - @property def default_pick_pack_action(self): return self.work.menu.default_pack_pickings_action @@ -334,20 +331,10 @@ def _data_for_packing_info(self, picking): # TODO: This could be avoided if included in the picking parser. return "" - def _data_response_for_select_package(self, picking, lines): - return { - "selected_move_lines": self._data_for_move_lines(lines.sorted()), - "picking": self.data.picking(picking), - "packing_info": self._data_for_packing_info(picking), - # "no_package_enabled": not self.options.get("checkout__disable_no_package"), - # Used by inheriting module - "package_allowed": True, - } - def _response_for_select_package(self, picking, lines, message=None): return self._response( next_state="select_package", - data=self._data_response_for_select_package(picking, lines), + data=self.data.select_package(picking, lines), message=message, ) diff --git a/shopfloor_packing/tests/__init__.py b/shopfloor_packing/tests/__init__.py index f4e45effd3..b3db59427f 100644 --- a/shopfloor_packing/tests/__init__.py +++ b/shopfloor_packing/tests/__init__.py @@ -1,5 +1,5 @@ -from . import ( # test_cluster_picking_pick_pack, - common, +from . import ( test_cluster_picking_pack_picking, + test_cluster_picking_pick_pack, test_cluster_picking_unload, ) diff --git a/shopfloor_packing/tests/test_cluster_picking_pick_pack.py b/shopfloor_packing/tests/test_cluster_picking_pick_pack.py index e35d7975f4..0eb3ee893f 100644 --- a/shopfloor_packing/tests/test_cluster_picking_pick_pack.py +++ b/shopfloor_packing/tests/test_cluster_picking_pick_pack.py @@ -1,4 +1,4 @@ -# Copyright 2021 ACSONE SA/NV +# Copyright 2024 ACSONE SA/NV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from .common import ClusterPickingUnloadPackingCommonCase @@ -34,6 +34,9 @@ def test_prepare_unload_all_same_dest_with_dest_package(self): next_state="pack_picking_scan_pack", data=data, ) + lines = picking.move_line_ids.filtered( + lambda ml: ml.result_package_id.is_internal + ).sorted(key=lambda ml: ml.result_package_id.name) # we scan the pack response = self.service.dispatch( "scan_packing_to_pack", @@ -43,7 +46,8 @@ def test_prepare_unload_all_same_dest_with_dest_package(self): "barcode": self.bin1.name, }, ) - data = self.data_detail.pack_picking_detail(picking) + + data = self.data.select_package(picking, lines) self.assert_response( response, next_state="select_package", @@ -69,6 +73,9 @@ def test_prepare_unload_all_same_dest_with_dest_package(self): self.assert_response( response, next_state="pack_picking_scan_pack", data=data, message=message ) + lines = picking.move_line_ids.filtered( + lambda ml: ml.result_package_id.is_internal + ).sorted(key=lambda ml: ml.result_package_id.name) # we scan the pack response = self.service.dispatch( "scan_packing_to_pack", @@ -78,10 +85,10 @@ def test_prepare_unload_all_same_dest_with_dest_package(self): "barcode": self.bin2.name, }, ) - data = self.data_detail.pack_picking_detail(picking) + data = self.data.select_package(picking, lines) self.assert_response( response, - next_state="pack_picking_put_in_pack", + next_state="select_package", data=data, ) # we process to the put in pack