Skip to content

Commit

Permalink
shopfloor: add option to order the picking list by priority
Browse files Browse the repository at this point in the history
  • Loading branch information
JuMiSanAr committed Nov 17, 2023
1 parent 4e65b68 commit 0aeb55f
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 5 deletions.
4 changes: 3 additions & 1 deletion shopfloor/actions/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions shopfloor/actions/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
21 changes: 21 additions & 0 deletions shopfloor/models/shopfloor_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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"
)
10 changes: 8 additions & 2 deletions shopfloor/services/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions shopfloor/tests/test_checkout_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions shopfloor/tests/test_checkout_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions shopfloor/views/shopfloor_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@
/>
<field name="show_oneline_package_content" />
</group>
<group
name="order_pickings_by_priority"
attrs="{'invisible': [('order_pickings_by_priority_is_possible', '=', False)]}"
>
<field
name="order_pickings_by_priority_is_possible"
invisible="1"
/>
<field name="order_pickings_by_priority" />
</group>
</group>
</field>
</record>
Expand Down

0 comments on commit 0aeb55f

Please sign in to comment.