Skip to content

Commit

Permalink
zone picking: return right amount of operations on picking types data (
Browse files Browse the repository at this point in the history
  • Loading branch information
sebalix authored and hparfr committed Dec 1, 2020
1 parent ce9c206 commit 82918c2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 50 deletions.
37 changes: 0 additions & 37 deletions shopfloor/actions/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,41 +234,4 @@ def _picking_type_parser(self):
return [
"id",
"name",
("lines_count", self._picking_type_lines_count),
("picking_count", self._picking_type_picking_count),
("priority_lines_count", self._picking_type_priority_lines_count),
("priority_picking_count", self._picking_type_priority_picking_count),
]

def _picking_type_lines_count(self, rec, field):
return self.env["stock.move.line"].search_count(
[
("picking_id.picking_type_id", "=", rec.id),
("qty_done", "=", 0),
("state", "in", ("assigned", "partially_available")),
]
)

def _picking_type_priority_lines_count(self, rec, field):
return self.env["stock.move.line"].search_count(
[
("picking_id.picking_type_id", "=", rec.id),
("qty_done", "=", 0),
("state", "in", ("assigned", "partially_available")),
("picking_id.priority", "in", ["2", "3"]),
]
)

def _picking_type_picking_count(self, rec, field):
return self.env["stock.picking"].search_count(
[("picking_type_id", "=", rec.id), ("state", "not in", ("cancel", "done"))]
)

def _picking_type_priority_picking_count(self, rec, field):
return self.env["stock.picking"].search_count(
[
("picking_type_id", "=", rec.id),
("state", "not in", ("cancel", "done")),
("priority", "in", ["2", "3"]),
]
)
4 changes: 0 additions & 4 deletions shopfloor/services/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,4 @@ def picking_type(self):
return {
"id": {"required": True, "type": "integer"},
"name": {"type": "string", "nullable": False, "required": True},
"lines_count": {"type": "float", "required": True},
"picking_count": {"type": "float", "required": True},
"priority_lines_count": {"type": "float", "required": True},
"priority_picking_count": {"type": "float", "required": True},
}
40 changes: 38 additions & 2 deletions shopfloor/services/zone_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,38 @@ def _response_for_unload_set_destination(
)

def _data_for_select_picking_type(self, zone_location, picking_types):
return {
data = {
"zone_location": self.data.location(zone_location),
# available picking types to choose from
"picking_types": self.data.picking_types(picking_types),
}
for datum in data["picking_types"]:
picking_type = self.env["stock.picking.type"].browse(datum["id"])
zone_lines = self._picking_type_zone_lines(zone_location, picking_type)
priority_lines = zone_lines.filtered(
lambda line: line.picking_id.priority in ["2", "3"]
)

datum.update(
{
"lines_count": len(zone_lines),
"picking_count": len(zone_lines.mapped("picking_id")),
"priority_lines_count": len(priority_lines),
"priority_picking_count": len(priority_lines.mapped("picking_id")),
}
)
return data

def _picking_type_zone_lines(self, zone_location, picking_type):
return self.env["stock.move.line"].search(
[
("location_id", "=", zone_location.id),
# we have auto_join on picking_id
("picking_id.picking_type_id", "=", picking_type.id),
("qty_done", "=", 0),
("state", "in", ("assigned", "partially_available")),
]
)

def _data_for_move_line(self, zone_location, picking_type, move_line):
return {
Expand Down Expand Up @@ -1401,9 +1428,18 @@ def unload_set_destination(self):

@property
def _schema_for_select_picking_type(self):
picking_type = self.schemas.picking_type()
picking_type.update(
{
"lines_count": {"type": "float", "required": True},
"picking_count": {"type": "float", "required": True},
"priority_lines_count": {"type": "float", "required": True},
"priority_picking_count": {"type": "float", "required": True},
}
)
schema = {
"zone_location": self.schemas._schema_dict_of(self.schemas.location()),
"picking_types": self.schemas._schema_list_of(self.schemas.picking_type()),
"picking_types": self.schemas._schema_list_of(picking_type),
}
return schema

Expand Down
9 changes: 2 additions & 7 deletions shopfloor/tests/test_zone_picking_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,9 @@ def assert_response_start(self, response, message=None):
def _assert_response_select_picking_type(
self, state, response, zone_location, picking_types, message=None
):
data = self.service._data_for_select_picking_type(zone_location, picking_types)
self.assert_response(
response,
next_state=state,
data={
"zone_location": self.data.location(zone_location),
"picking_types": self.data.picking_types(picking_types),
},
message=message,
response, next_state=state, data=data, message=message,
)

def assert_response_select_picking_type(
Expand Down

0 comments on commit 82918c2

Please sign in to comment.