Skip to content

Commit

Permalink
Merge PR #770 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by sebalix
  • Loading branch information
OCA-git-bot committed Nov 14, 2023
2 parents 0d0507f + 0fcc5c4 commit 05efaa3
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 6 deletions.
4 changes: 3 additions & 1 deletion shopfloor/actions/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ 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")
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):
Expand Down
1 change: 1 addition & 0 deletions shopfloor/actions/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
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 @@ -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"
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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"
)
10 changes: 8 additions & 2 deletions shopfloor/services/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
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 @@ -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)
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
13 changes: 12 additions & 1 deletion shopfloor/views/shopfloor_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
name="scan_location_or_pack_first"
attrs="{'invisible': [('scan_location_or_pack_first_is_possible', '=', False)]}"
>
<field name="scenario_key" invisible="1" />
<field name="scan_location_or_pack_first_is_possible" invisible="1" />
<field name="scan_location_or_pack_first" />
<div
Expand Down Expand Up @@ -167,7 +168,17 @@
invisible="1"
/>
<field name="allow_alternative_destination_package" />
</group>
</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
1 change: 1 addition & 0 deletions shopfloor_mobile/static/wms/src/scenario/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ const Checkout = {
{path: "origin"},
{path: "carrier.name", label: "Carrier"},
{path: "move_line_count", label: "Lines"},
{path: "priority", label: "Priority"},
],
},
};
Expand Down

0 comments on commit 05efaa3

Please sign in to comment.