[FIX] code cleanup (addon fleet)
improve the _count_all method by removing try/catch/pass and by using search_count instead of the one2many relation. Also, removes now useless one2many fields costs_ids and odometer_ids bzr revid: ged@openerp.com-20140507075645-2tp5zgayeea9ehv2
This commit is contained in:
parent
c941eb8ca4
commit
0a9a393010
|
@ -315,18 +315,21 @@ class fleet_vehicle(osv.Model):
|
||||||
return model_id
|
return model_id
|
||||||
|
|
||||||
def _count_all(self, cr, uid, ids, field_name, arg, context=None):
|
def _count_all(self, cr, uid, ids, field_name, arg, context=None):
|
||||||
res = dict(map(lambda x: (x,{'odometer_count': 0, 'fuel_logs_count': 0, 'service_count': 0, 'contract_count': 0, 'cost_count': 0,}), ids))
|
Odometer = self.pool['fleet.vehicle.odometer']
|
||||||
try:
|
LogFuel = self.pool['fleet.vehicle.log.fuel']
|
||||||
for costs in self.browse(cr, uid, ids, context=context):
|
LogService = self.pool['fleet.vehicle.log.services']
|
||||||
res[costs.id] = {'odometer_count': len(costs.odometer_ids),
|
LogContract = self.pool['fleet.vehicle.log.contract']
|
||||||
'fuel_logs_count': len(costs.log_fuel),
|
Cost = self.pool['fleet.vehicle.cost']
|
||||||
'service_count': len(costs.log_services),
|
return {
|
||||||
'contract_count': len(costs.log_contracts),
|
vehicle_id: {
|
||||||
'cost_count': len(costs.costs_ids)
|
'odometer_count': Odometer.search_count(cr, uid, [('vehicle_id', '=', vehicle_id)], context=context),
|
||||||
}
|
'fuel_logs_count': LogFuel.search_count(cr, uid, [('vehicle_id', '=', vehicle_id)], context=context),
|
||||||
except:
|
'service_count': LogService.search_count(cr, uid, [('vehicle_id', '=', vehicle_id)], context=context),
|
||||||
pass
|
'contract_count': LogContract.search_count(cr, uid, [('vehicle_id', '=', vehicle_id)], context=context),
|
||||||
return res
|
'cost_count': Cost.search_count(cr, uid, [('vehicle_id', '=', vehicle_id), ('parent_id', '=', False)], context=context)
|
||||||
|
}
|
||||||
|
for vehicle_id in ids
|
||||||
|
}
|
||||||
|
|
||||||
_name = 'fleet.vehicle'
|
_name = 'fleet.vehicle'
|
||||||
_description = 'Information on a vehicle'
|
_description = 'Information on a vehicle'
|
||||||
|
@ -341,8 +344,6 @@ class fleet_vehicle(osv.Model):
|
||||||
'log_fuel': fields.one2many('fleet.vehicle.log.fuel', 'vehicle_id', 'Fuel Logs'),
|
'log_fuel': fields.one2many('fleet.vehicle.log.fuel', 'vehicle_id', 'Fuel Logs'),
|
||||||
'log_services': fields.one2many('fleet.vehicle.log.services', 'vehicle_id', 'Services Logs'),
|
'log_services': fields.one2many('fleet.vehicle.log.services', 'vehicle_id', 'Services Logs'),
|
||||||
'log_contracts': fields.one2many('fleet.vehicle.log.contract', 'vehicle_id', 'Contracts'),
|
'log_contracts': fields.one2many('fleet.vehicle.log.contract', 'vehicle_id', 'Contracts'),
|
||||||
'costs_ids': fields.one2many('fleet.vehicle.cost', 'vehicle_id', 'Costs'),
|
|
||||||
'odometer_ids': fields.one2many('fleet.vehicle.odometer', 'vehicle_id', 'Odometer'),
|
|
||||||
'cost_count': fields.function(_count_all, type='integer', string="Costs" , multi=True),
|
'cost_count': fields.function(_count_all, type='integer', string="Costs" , multi=True),
|
||||||
'contract_count': fields.function(_count_all, type='integer', string='Contracts', multi=True),
|
'contract_count': fields.function(_count_all, type='integer', string='Contracts', multi=True),
|
||||||
'service_count': fields.function(_count_all, type='integer', string='Services', multi=True),
|
'service_count': fields.function(_count_all, type='integer', string='Services', multi=True),
|
||||||
|
|
Loading…
Reference in New Issue