Skip to content
Snippets Groups Projects
Commit 45585f73 authored by Yogesh Parekh's avatar Yogesh Parekh
Browse files

[IMP]: Convert buttons into stat buttons in fleet module

bzr revid: ypa@tinyerp.com-20140326122023-glwfkl5nwowq5i2e
parent b86c9ccd
Branches
Tags
No related merge requests found
......@@ -313,6 +313,20 @@ class fleet_vehicle(osv.Model):
except ValueError:
model_id = False
return model_id
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))
try:
for costs in self.browse(cr, uid, ids, context=context):
res[costs.id] = {'odometer_count': len(costs.odometer_ids),
'fuel_logs_count': len(costs.log_fuel),
'service_count': len(costs.log_services),
'contract_count': len(costs.log_contracts),
'cost_count': len(costs.costs_ids)
}
except:
pass
return res
_name = 'fleet.vehicle'
_description = 'Information on a vehicle'
......@@ -327,6 +341,13 @@ class fleet_vehicle(osv.Model):
'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_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),
'contract_count': fields.function(_count_all, type='integer', string='Contracts', multi=True),
'service_count': fields.function(_count_all, type='integer', string='Services', multi=True),
'fuel_logs_count': fields.function(_count_all, type='integer', string='Fuel Logs', multi=True),
'odometer_count': fields.function(_count_all, type='integer', string='Odometer', multi=True),
'acquisition_date': fields.date('Acquisition Date', required=False, help='Date when the vehicle has been bought'),
'color': fields.char('Color', size=32, help='Color of the vehicle'),
'state_id': fields.many2one('fleet.vehicle.state', 'State', help='Current state of the vehicle', ondelete="set null"),
......
......@@ -211,11 +211,46 @@
<field name="tag_ids" widget="many2many_tags" />
</div>
<div class="oe_right oe_button_box">
<button name="return_action_to_open" type="object" context="{'xml_id':'fleet_vehicle_log_contract_act'}" string="Contracts" help="show the contract for this vehicle" />
<button name="act_show_log_cost" type="object" string="Costs" help="show all the costs for this vehicle" groups="fleet.group_fleet_manager"/>
<button name="return_action_to_open" type="object" context="{'xml_id':'fleet_vehicle_log_services_act'}" string="Services" help="show the services logs for this vehicle" />
<button name="return_action_to_open" type="object" context="{'xml_id':'fleet_vehicle_log_fuel_act'}" string="Fuel Logs" help="show the fuel logs for this vehicle" />
<button name="return_action_to_open" type="object" context="{'xml_id':'fleet_vehicle_odometer_act'}" string="Odometer Logs" help="show the odometer logs for this vehicle" />
<button name="return_action_to_open"
type="object"
class="oe_stat_button"
icon="fa-thumbs-o-up"
context="{'xml_id':'fleet_vehicle_log_contract_act'}"
help="show the contract for this vehicle">
<field name="contract_count" widget="statinfo" string="Contracts"/>
</button>
<button name="act_show_log_cost"
type="object"
class="oe_stat_button"
icon="fa-money"
help="show all the costs for this vehicle"
groups="fleet.group_fleet_manager">
<field name="cost_count" widget="statinfo" string="Costs"/>
</button>
<button name="return_action_to_open"
type="object"
class="oe_stat_button"
icon="fa-wrench"
context="{'xml_id':'fleet_vehicle_log_services_act'}"
help="show the services logs for this vehicle" >
<field name="service_count" widget="statinfo" string="Services"/>
</button>
<button name="return_action_to_open"
type="object"
class="oe_stat_button"
icon="fa-flask"
context="{'xml_id':'fleet_vehicle_log_fuel_act'}"
help="show the fuel logs for this vehicle" >
<field name="fuel_logs_count" widget="statinfo" string="Fuel Logs"/>
</button>
<button name="return_action_to_open"
type="object"
class="oe_stat_button"
icon="fa-tachometer"
context="{'xml_id':'fleet_vehicle_odometer_act'}"
help="show the odometer logs for this vehicle" >
<field name="odometer_count" widget="statinfo" string="odometer Logs"/>
</button>
</div>
<group col="2" string="General Properties">
<group >
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment