diff --git a/shopfloor/actions/data.py b/shopfloor/actions/data.py index f2d7d1bd76..b45da63a28 100644 --- a/shopfloor/actions/data.py +++ b/shopfloor/actions/data.py @@ -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"]), - ] - ) diff --git a/shopfloor/services/schema.py b/shopfloor/services/schema.py index cf0689f480..16da390bb2 100644 --- a/shopfloor/services/schema.py +++ b/shopfloor/services/schema.py @@ -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}, } diff --git a/shopfloor/services/zone_picking.py b/shopfloor/services/zone_picking.py index 81292dd388..26135c74f0 100644 --- a/shopfloor/services/zone_picking.py +++ b/shopfloor/services/zone_picking.py @@ -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 { @@ -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 diff --git a/shopfloor/tests/test_zone_picking_base.py b/shopfloor/tests/test_zone_picking_base.py index ddd2897411..097e7e0e15 100644 --- a/shopfloor/tests/test_zone_picking_base.py +++ b/shopfloor/tests/test_zone_picking_base.py @@ -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(