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

Module: Fleet

Entity: fleet.vehicle

Compute Method: _compute_count_all

Inputs Method Outputs
Odometer = self.env['fleet.vehicle.odometer']
LogService = self.env['fleet.vehicle.log.services'].with_context(active_test=False)
LogContract = self.env['fleet.vehicle.log.contract'].with_context(active_test=False)
History = self.env['fleet.vehicle.assignation.log']
odometers_data = Odometer._read_group([('vehicle_id', 'in', self.ids)], ['vehicle_id'], ['__count'])
services_data = LogService._read_group([('vehicle_id', 'in', self.ids)], ['vehicle_id', 'active'], ['__count'])
logs_data = LogContract._read_group([('vehicle_id', 'in', self.ids), ('state', '!=', 'closed')], ['vehicle_id', 'active'], ['__count'])
histories_data = History._read_group([('vehicle_id', 'in', self.ids)], ['vehicle_id'], ['__count'])
mapped_odometer_data = defaultdict(lambda: 0)
mapped_service_data = defaultdict(lambda: defaultdict(lambda: 0))
mapped_log_data = defaultdict(lambda: defaultdict(lambda: 0))
mapped_history_data = defaultdict(lambda: 0)
for vehicle, count in odometers_data:
            mapped_odometer_data[vehicle.id] = count
for vehicle, active, count in services_data:
            mapped_service_data[vehicle.id][active] = count
for vehicle, active, count in logs_data:
            mapped_log_data[vehicle.id][active] = count
for vehicle, count in histories_data:
            mapped_history_data[vehicle.id] = count
for vehicle in self:
            vehicle.odometer_count = mapped_odometer_data[vehicle.id]
            vehicle.service_count = mapped_service_data[vehicle.id][vehicle.active]
            vehicle.contract_count = mapped_log_data[vehicle.id][vehicle.active]
            vehicle.history_count = mapped_history_data[vehicle.id]

Back to entity