Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Stock Fleet Delivery Driver

Entity: stock.picking.batch

Compute Method: _compute_vehicle_id

Inputs Method Outputs
"""Compute default vehicle based on how many vehicles are used in pickings."""
for record in self.filtered_domain([("vehicle_id", "=", False)]):
            vehicle_count_dict = defaultdict(lambda: 0)
            for picking in record.picking_ids.filtered(
                lambda picking: picking.state not in {"done", "cancel"}
                and picking.vehicle_id
            ):
                vehicle_count_dict[picking.vehicle_id] += 1
            if not vehicle_count_dict:
                continue
            vehicle_count_data = sorted(
                list(vehicle_count_dict.items()),
                key=lambda vehicle_data: vehicle_data[1],
                reverse=True,
            )
            record.vehicle_id = vehicle_count_data[0][0]

Back to entity