diff --git a/shopfloor/actions/data.py b/shopfloor/actions/data.py index 1454636b03..e187c245ab 100644 --- a/shopfloor/actions/data.py +++ b/shopfloor/actions/data.py @@ -36,10 +36,12 @@ def picking(self, record, **kw): # Thus, we make it optional. if "with_progress" in kw: parser.append("progress") + if kw.get("with_priority"): + parser.append("priority") return self._jsonify(record, parser, **kw) def pickings(self, record, **kw): - return self.picking(record, multi=True) + return self.picking(record, multi=True, **kw) @property def _picking_parser(self, **kw): diff --git a/shopfloor/actions/schema.py b/shopfloor/actions/schema.py index bdfab9801b..77c179c126 100644 --- a/shopfloor/actions/schema.py +++ b/shopfloor/actions/schema.py @@ -26,6 +26,7 @@ def picking(self): "ship_carrier": self._schema_dict_of(self._simple_record(), required=False), "scheduled_date": {"type": "string", "nullable": False, "required": True}, "progress": {"type": "float", "nullable": True}, + "priority": {"type": "string", "nullable": True, "required": False}, } def move_line(self, with_packaging=False, with_picking=False): diff --git a/shopfloor/models/shopfloor_menu.py b/shopfloor/models/shopfloor_menu.py index a01da9f417..8e6fe96d28 100644 --- a/shopfloor/models/shopfloor_menu.py +++ b/shopfloor/models/shopfloor_menu.py @@ -33,6 +33,12 @@ (i.e. +1 Unit or +1 Box) """ +ALLOW_ORDER_PICKINGS_BY_PRIORITY_HELP = """ +When listing all pickings in the scenario, display the priority number +(corresponding to the stars in each transfer in Odoo) +and order them by priority as well. +""" + class ShopfloorMenu(models.Model): _inherit = "shopfloor.menu" @@ -158,6 +164,14 @@ class ShopfloorMenu(models.Model): show_oneline_package_content_is_possible = fields.Boolean( compute="_compute_show_oneline_package_content_is_possible" ) + order_pickings_by_priority = fields.Boolean( + string="Order pickings by priority", + default=False, + help=ALLOW_ORDER_PICKINGS_BY_PRIORITY_HELP, + ) + order_pickings_by_priority_is_possible = fields.Boolean( + compute="_compute_order_pickings_by_priority_is_possible" + ) @api.onchange("unload_package_at_destination") def _onchange_unload_package_at_destination(self): @@ -367,3 +381,10 @@ def _compute_show_oneline_package_content_is_possible(self): menu.show_oneline_package_content_is_possible = menu.scenario_id.has_option( "show_oneline_package_content" ) + + @api.depends("scenario_id") + def _compute_order_pickings_by_priority_is_possible(self): + for menu in self: + menu.order_pickings_by_priority_is_possible = menu.scenario_id.has_option( + "order_pickings_by_priority" + ) diff --git a/shopfloor/services/checkout.py b/shopfloor/services/checkout.py index e527a5a185..66d740c44d 100644 --- a/shopfloor/services/checkout.py +++ b/shopfloor/services/checkout.py @@ -84,7 +84,10 @@ def _response_for_manual_selection(self, message=None): self._domain_for_list_stock_picking(), order=self._order_for_list_stock_picking(), ) - data = {"pickings": self.data.pickings(pickings)} + order_by_priority = self.work.menu.order_pickings_by_priority + data = { + "pickings": self.data.pickings(pickings, with_priority=order_by_priority) + } return self._response(next_state="manual_selection", data=data, message=message) def _response_for_select_package(self, picking, lines, message=None): @@ -348,7 +351,10 @@ def _domain_for_list_stock_picking(self): ] def _order_for_list_stock_picking(self): - return "scheduled_date asc, id asc" + base_order = "scheduled_date asc, id asc" + if self.work.menu.order_pickings_by_priority: + return "priority desc, " + base_order + return base_order def list_stock_picking(self): """List stock.picking records available diff --git a/shopfloor/tests/test_checkout_base.py b/shopfloor/tests/test_checkout_base.py index 0a327da2a9..a008dc9cdf 100644 --- a/shopfloor/tests/test_checkout_base.py +++ b/shopfloor/tests/test_checkout_base.py @@ -27,8 +27,8 @@ def _stock_picking_data(self, picking, **kw): return self.service._data_for_stock_picking(picking, **kw) # we test the methods that structure data in test_actions_data.py - def _picking_summary_data(self, picking): - return self.data.picking(picking) + def _picking_summary_data(self, picking, **kw): + return self.data.picking(picking, **kw) def _move_line_data(self, move_line): return self.data.move_line(move_line) diff --git a/shopfloor/tests/test_checkout_select.py b/shopfloor/tests/test_checkout_select.py index 13f4322256..61c831f841 100644 --- a/shopfloor/tests/test_checkout_select.py +++ b/shopfloor/tests/test_checkout_select.py @@ -24,6 +24,33 @@ def test_list_stock_picking(self): self.assert_response(response, next_state="manual_selection", data=expected) + def test_list_stock_picking_order_by_priority(self): + self.menu.sudo().order_pickings_by_priority = True + # Pickings should be ordered by priority, + # and they should also return their priority number to the frontend. + picking1 = self._create_picking() + picking1.priority = "0" + picking2 = self._create_picking() + picking2.priority = "1" + picking3 = self._create_picking() + picking3.priority = "1" + picking4 = self._create_picking() + picking4.priority = "0" + to_assign = picking1 | picking2 | picking3 | picking4 + self._fill_stock_for_moves(to_assign.move_lines, in_package=True) + to_assign.action_assign() + response = self.service.dispatch("list_stock_picking", params={}) + expected = { + "pickings": [ + self._picking_summary_data(picking2, with_priority=True), + self._picking_summary_data(picking3, with_priority=True), + self._picking_summary_data(picking1, with_priority=True), + self._picking_summary_data(picking4, with_priority=True), + ] + } + + self.assert_response(response, next_state="manual_selection", data=expected) + class CheckoutSelectCase(CheckoutCommonCase): @classmethod diff --git a/shopfloor/views/shopfloor_menu.xml b/shopfloor/views/shopfloor_menu.xml index 63d9de08d7..c604d1c0b4 100644 --- a/shopfloor/views/shopfloor_menu.xml +++ b/shopfloor/views/shopfloor_menu.xml @@ -108,6 +108,16 @@ /> + + + +