[IMP] fleet: Clean some views and add useful piece of information

PURPOSE
=======

During the Salary Package Configurator implementation, some improvement have been made to improve the fleet management module

- When duplicating a fleet vehicle cost (for example when duplication a vehicle contract), duplicate the included costs too.
- Add a field Cost Description on the list view
- Rename 'Acquisition Date' into 'Immatriculation Date'
- Rename 'Car Value' into 'Catalog Value (VAT incl.)'
- Add a information field 'Residual Value on a vehicle'
- Prevent an employee to have several cars
- Only display opened contract on the vehicle form view
- Add the driver on the odometer list view
- Rename 'Odometer value' into 'Odometer at creation' on a vehicle contract
- Restructure to vehicle model form view to be bearable by a human eye
- Show the handle widget on the fleet vehicle state list view
- Show configuration menuitems to fleet managers, not only debug mode
This commit is contained in:
Yannick Tivisse
2017-04-26 15:08:09 +02:00
parent f6f342e50b
commit 2e7cdc1c90
2 changed files with 65 additions and 42 deletions
+14 -4
View File
@@ -18,13 +18,14 @@ class FleetVehicleCost(models.Model):
cost_type = fields.Selection([('contract', 'Contract'), ('services', 'Services'), ('fuel', 'Fuel'), ('other', 'Other')],
'Category of the cost', default="other", help='For internal purpose only', required=True)
parent_id = fields.Many2one('fleet.vehicle.cost', 'Parent', help='Parent cost to this current cost')
cost_ids = fields.One2many('fleet.vehicle.cost', 'parent_id', 'Included Services')
cost_ids = fields.One2many('fleet.vehicle.cost', 'parent_id', 'Included Services', copy=True)
odometer_id = fields.Many2one('fleet.vehicle.odometer', 'Odometer', help='Odometer measure of the vehicle at the moment of this log')
odometer = fields.Float(compute="_get_odometer", inverse='_set_odometer', string='Odometer Value', help='Odometer measure of the vehicle at the moment of this log')
odometer_unit = fields.Selection(related='vehicle_id.odometer_unit', string="Unit", readonly=True)
date = fields.Date(help='Date when the cost has been executed')
contract_id = fields.Many2one('fleet.vehicle.log.contract', 'Contract', help='Contract attached to this cost')
auto_generated = fields.Boolean('Automatically Generated', readonly=True)
description = fields.Char("Cost Description")
def _get_odometer(self):
for record in self:
@@ -160,7 +161,7 @@ class FleetVehicle(models.Model):
service_count = fields.Integer(compute="_compute_count_all", string='Services')
fuel_logs_count = fields.Integer(compute="_compute_count_all", string='Fuel Logs')
odometer_count = fields.Integer(compute="_compute_count_all", string='Odometer')
acquisition_date = fields.Date('Acquisition Date', required=False, help='Date when the vehicle has been bought')
acquisition_date = fields.Date('Immatriculation Date', required=False, help='Date when the vehicle has been immatriculated')
color = fields.Char(help='Color of the vehicle')
state_id = fields.Many2one('fleet.vehicle.state', 'State', default=_get_default_state, help='Current state of the vehicle', ondelete="set null")
location = fields.Char(help='Location of the vehicle (garage, ...)')
@@ -183,7 +184,12 @@ class FleetVehicle(models.Model):
contract_renewal_overdue = fields.Boolean(compute='_compute_contract_reminder', search='_search_get_overdue_contract_reminder', string='Has Contracts Overdue', multi='contract_info')
contract_renewal_name = fields.Text(compute='_compute_contract_reminder', string='Name of contract to renew soon', multi='contract_info')
contract_renewal_total = fields.Text(compute='_compute_contract_reminder', string='Total of contracts due or overdue minus one', multi='contract_info')
car_value = fields.Float(help='Value of the bought vehicle')
car_value = fields.Float(string="Catalog Value (VAT incl.)", help='Value of the bought vehicle')
residual_value = fields.Float()
_sql_constraints = [
('driver_id_unique', 'UNIQUE(driver_id)', 'Only one car can be assigned to the same employee!')
]
@api.depends('model_id', 'license_plate')
def _compute_vehicle_name(self):
@@ -216,7 +222,7 @@ class FleetVehicle(models.Model):
record.odometer_count = Odometer.search_count([('vehicle_id', '=', record.id)])
record.fuel_logs_count = LogFuel.search_count([('vehicle_id', '=', record.id)])
record.service_count = LogService.search_count([('vehicle_id', '=', record.id)])
record.contract_count = LogContract.search_count([('vehicle_id', '=', record.id)])
record.contract_count = LogContract.search_count([('vehicle_id', '=', record.id), ('state', '=', 'open')])
record.cost_count = Cost.search_count([('vehicle_id', '=', record.id), ('parent_id', '=', False)])
@api.depends('log_contracts')
@@ -336,6 +342,8 @@ class FleetVehicle(models.Model):
return super(FleetVehicle, self).write(vals)
# TODO: Split models in hr_payroll and fleet into several files (this is a real pain in the arse)
@api.multi
def return_action_to_open(self):
""" This opens the xml view specified in xml_id for the current vehicle """
@@ -373,6 +381,7 @@ class FleetVehicleOdometer(models.Model):
value = fields.Float('Odometer Value', group_operator="max")
vehicle_id = fields.Many2one('fleet.vehicle', 'Vehicle', required=True)
unit = fields.Selection(related='vehicle_id.odometer_unit', string="Unit", readonly=True)
driver_id = fields.Many2one(related="vehicle_id.driver_id", string="Driver")
@api.depends('vehicle_id', 'date')
def _compute_vehicle_log_name(self):
@@ -522,6 +531,7 @@ class FleetVehicleLogContract(models.Model):
sum_cost = fields.Float(compute='_compute_sum_cost', string='Indicative Costs Total')
cost_id = fields.Many2one('fleet.vehicle.cost', 'Cost', required=True, ondelete='cascade')
cost_amount = fields.Float(related='cost_id.amount', string='Amount', store=True) # we need to keep this field as a related with store=True because the graph view doesn't support (1) to address fields from inherited table and (2) fields that aren't stored in database
odometer = fields.Float(string='Odometer at creation', help='Odometer measure of the vehicle at the moment of the contract creation')
@api.depends('vehicle_id', 'cost_subtype_id', 'date')
def _compute_contract_name(self):
+51 -38
View File
@@ -5,38 +5,40 @@
<field name="model">fleet.vehicle.model</field>
<field name="arch" type="xml">
<form string="Model">
<field name="image_medium" widget='image' class="oe_avatar"/>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1>
<field name="name" placeholder="e.g. Model S"/>
</h1>
<label for="brand_id" class="oe_edit_only"/>
<h2>
<field name="brand_id" placeholder="e.g. Tesla"/>
</h2>
</div>
<notebook>
<page string="Vendors">
<field name="vendors">
<kanban quick_create="false" create="true">
<field name="name"/>
<templates>
<t t-name="kanban-box">
<div style="position: relative">
<a t-if="! read_only_mode" type="delete" style="position: absolute; right: 0; padding: 4px; diplay: inline-block">X</a>
<div class="oe_module_vignette">
<div class="oe_module_desc">
<field name="name"/>
<sheet>
<field name="image_medium" widget='image' class="oe_avatar"/>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1>
<field name="name" placeholder="e.g. Model S"/>
</h1>
<label for="brand_id" class="oe_edit_only"/>
<h2>
<field name="brand_id" placeholder="e.g. Tesla"/>
</h2>
</div>
<notebook>
<page string="Vendors" name="vendors">
<field name="vendors" widget="many2many_kanban">
<kanban quick_create="false" create="true">
<field name="name"/>
<templates>
<t t-name="kanban-box">
<div style="position: relative">
<a t-if="! read_only_mode" type="delete" style="position: absolute; right: 0; padding: 4px; diplay: inline-block">X</a>
<div class="oe_module_vignette">
<div class="oe_module_desc">
<field name="name"/>
</div>
</div>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</page>
</notebook>
</t>
</templates>
</kanban>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
@@ -153,7 +155,7 @@
<field name="model">fleet.vehicle.state</field>
<field name="arch" type="xml">
<tree string="State" editable="bottom">
<field name="sequence" widget="handler" invisible="1"/>
<field name="sequence" widget="handler"/>
<field name="name" />
</tree>
@@ -177,8 +179,8 @@
<menuitem name="Fleet" id="menu_root" sequence="115" groups="fleet_group_user" web_icon="fleet,static/description/icon.png"/>
<menuitem name="Configuration" parent="menu_root" id="fleet_configuration" sequence="100" groups="fleet_group_manager"/>
<menuitem action="fleet_vehicle_model_action" parent="fleet_configuration" id="fleet_vehicle_model_menu" groups="base.group_no_one"/>
<menuitem action="fleet_vehicle_model_brand_action" parent="fleet_configuration" id="fleet_vehicle_model_brand_menu" groups="base.group_no_one"/>
<menuitem action="fleet_vehicle_model_action" parent="fleet_configuration" id="fleet_vehicle_model_menu"/>
<menuitem action="fleet_vehicle_model_brand_action" parent="fleet_configuration" id="fleet_vehicle_model_brand_menu"/>
<menuitem action="fleet_vehicle_state_action" parent="fleet_configuration" id="fleet_vehicle_state_menu" groups="fleet_group_manager"/>
<record id='fleet_vehicle_view_form' model='ir.ui.view'>
@@ -195,7 +197,7 @@
type="object"
class="oe_stat_button"
icon="fa-book"
context="{'xml_id':'fleet_vehicle_log_contract_action'}"
context="{'xml_id':'fleet_vehicle_log_contract_action', 'search_default_open': 1}"
help="show the contract for this vehicle">
<field name="contract_count" widget="statinfo" string="Contracts"/>
</button>
@@ -263,6 +265,7 @@
</div>
<field name="acquisition_date" />
<field name="car_value" />
<field name="residual_value"/>
</group>
</group>
<group col="2">
@@ -275,7 +278,7 @@
<field name="transmission" />
<field name="fuel_type" />
<label for="co2"/>
<div class="o_row">
<div class="o_row" name="co2">
<field name="co2"/><span>g/km</span>
</div>
<field name="horsepower" />
@@ -472,12 +475,17 @@
<field name="cost_ids" context="{'vehicle_id': vehicle_id}" nolabel="1">
<tree editable="bottom">
<field name="cost_subtype_id" string="Service" domain="[('category','=','service')]"/>
<field name="description"/>
<field name="amount" sum="Price" string="Indicative Cost" />
</tree>
</field>
</group>
<div class="oe_right"><group><field name="sum_cost" string="Indicative Costs Total"/></group></div>
<div class="oe_right">
<group>
<field name="sum_cost" string="Indicative Costs Total"/>
</group>
</div>
</page>
<page string="Generated Recurring Costs">
<group>
@@ -547,6 +555,7 @@
<field name="arch" type="xml">
<search string="Vehicles Contracts">
<filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
<filter string="In Progress" name="open" domain="[('state', '=', 'open')]"/>
</search>
</field>
</record>
@@ -556,6 +565,7 @@
<field name="res_model">fleet.vehicle.log.contract</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,graph</field>
<field name="context">{'search_default_open': 1}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a new contract.
@@ -598,6 +608,7 @@
<tree string="Odometer Logs" editable="top">
<field name="date" />
<field name="vehicle_id"/>
<field name="driver_id"/>
<field name="value" />
<field name="unit" />
</tree>
@@ -880,7 +891,7 @@
</field>
</record>
<menuitem id="fleet_vehicle_tag_menu" parent="fleet_configuration" action="fleet_vehicle_tag_action" sequence="112" groups="base.group_no_one"/>
<menuitem id="fleet_vehicle_tag_menu" parent="fleet_configuration" action="fleet_vehicle_tag_action" sequence="112"/>
<record id='fleet_vehicle_service_types_view_tree' model='ir.ui.view'>
<field name="name">fleet.service.type.tree</field>
@@ -910,7 +921,7 @@
</field>
</record>
<menuitem action="fleet_vehicle_service_types_action" parent="fleet_configuration" id="fleet_vehicle_service_types_menu" groups="base.group_no_one"/>
<menuitem action="fleet_vehicle_service_types_action" parent="fleet_configuration" id="fleet_vehicle_service_types_menu"/>
<record id='fleet_vehicle_cost_view_tree' model='ir.ui.view'>
<field name="name">fleet.vehicle.cost.tree</field>
@@ -918,6 +929,7 @@
<field name="arch" type="xml">
<tree string="Vehicle Costs">
<field name="vehicle_id"/>
<field name="description"/>
<field name="cost_subtype_id"/>
<field name="date"/>
</tree>
@@ -1008,6 +1020,7 @@
<field name="vehicle_id" />
<field name="cost_subtype_id"/>
<field name="amount"/>
<field name="description"/>
</group>
<group>
<field name="date"/>