Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions shopfloor/services/cluster_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _response_for_start_line(
self, move_line, message=None, popup=None, sublocation=None
):
kw = {"sublocation": self.data.location(sublocation)} if sublocation else {}
data = self._data_move_line(move_line, **kw)
data = self._data_move_line(move_line, no_qty_available=True, **kw)
return self._response(
next_state="start_line",
data=data,
Expand All @@ -107,9 +107,14 @@ def _response_for_start_line(

def _response_for_scan_destination(self, move_line, message=None, qty_done=None):
if qty_done is None:
data = self._data_move_line(move_line)
data = self._data_move_line(
move_line,
no_qty_available=True,
)
else:
data = self._data_move_line(move_line, qty_done=qty_done)
data = self._data_move_line(
move_line, no_qty_available=True, qty_done=qty_done
)
last_picked_line = self._last_picked_line(move_line.picking_id)
if last_picked_line:
# suggest pack to be used for the next line
Expand Down Expand Up @@ -406,9 +411,10 @@ def _data_move_line(self, line, **kw):
data["batch"] = self.data.picking_batch(batch)
data["picking"] = self.data.picking(picking)
data["postponed"] = line.shopfloor_postponed
data["product"]["qty_available"] = product.with_context(
location=line.location_id.id
).qty_available
if "no_qty_available" not in kw or not kw.get("no_qty_available"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not simply this?

Suggested change
if "no_qty_available" not in kw or not kw.get("no_qty_available"):
if not kw.get("no_qty_available"):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data["product"]["qty_available"] = product.with_context(
location=line.location_id.id
).qty_available
Comment on lines +414 to +417
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to avoid double negations ? not no_qty_available is not really intuitive to read.
For instance, explicitely add a named argument with_qty_available which defaults to True.
When you don't need this information in the data, we can just set with_qty_available=False.
Then you can do this, which IMO is easier to read. and less bug prone.

Suggested change
if "no_qty_available" not in kw or not kw.get("no_qty_available"):
data["product"]["qty_available"] = product.with_context(
location=line.location_id.id
).qty_available
if with_qty_available:
data["product"]["qty_available"] = product.with_context(
location=line.location_id.id
).qty_available

What do you think ?

data["scan_location_or_pack_first"] = self.work.menu.scan_location_or_pack_first
data.update(kw)
return data
Expand Down