diff --git a/shopfloor/actions/data.py b/shopfloor/actions/data.py
index aaefbc06dc..19a4a151d4 100644
--- a/shopfloor/actions/data.py
+++ b/shopfloor/actions/data.py
@@ -48,6 +48,8 @@ def _get_picking_parser(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 parser
@ensure_model("stock.picking")
@@ -55,7 +57,7 @@ def picking(self, record, **kw):
return self._jsonify(record, self._get_picking_parser(record, **kw), **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 bfa0fdba4e..e474fe35de 100644
--- a/shopfloor/actions/schema.py
+++ b/shopfloor/actions/schema.py
@@ -27,6 +27,7 @@ def picking(self):
"scheduled_date": {"type": "string", "nullable": False, "required": True},
"progress": {"type": "float", "nullable": True},
"location_dest": self._schema_dict_of(self.location(), required=False),
+ "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 7521a67db4..6067bb0a5c 100644
--- a/shopfloor/models/shopfloor_menu.py
+++ b/shopfloor/models/shopfloor_menu.py
@@ -53,6 +53,12 @@
to scan a destination package.
"""
+ALLOW_ORDER_PICKINGS_BY_PRIORITY_HELP = """
+When listing all transfers 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"
@@ -226,6 +232,14 @@ class ShopfloorMenu(models.Model):
allow_alternative_destination_package_is_possible = fields.Boolean(
compute="_compute_allow_alternative_destination_package_is_possible"
)
+ order_pickings_by_priority = fields.Boolean(
+ string="Order transfers 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):
@@ -455,3 +469,10 @@ def _compute_allow_alternative_destination_package_is_possible(self):
menu.allow_alternative_destination_package_is_possible = (
menu.scenario_id.has_option("allow_alternative_destination_package")
)
+
+ @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 01b8b6c81b..f8bd61d2bb 100644
--- a/shopfloor/services/checkout.py
+++ b/shopfloor/services/checkout.py
@@ -91,7 +91,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):
@@ -360,7 +363,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 120e1e71af..e4fef0bfe0 100644
--- a/shopfloor/tests/test_checkout_base.py
+++ b/shopfloor/tests/test_checkout_base.py
@@ -34,8 +34,8 @@ def _stock_locations_data(self, locations, **kw):
return self.service._data_for_locations(locations, **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 868dc85c6c..4dadf7bd08 100644
--- a/shopfloor/views/shopfloor_menu.xml
+++ b/shopfloor/views/shopfloor_menu.xml
@@ -112,6 +112,7 @@
name="scan_location_or_pack_first"
attrs="{'invisible': [('scan_location_or_pack_first_is_possible', '=', False)]}"
>
+