[IMP] (hr_)fleet: usability changes (b2b)

Minor usability changes:

  * Reorganize menu to be more consistent with other HR apps;
  * Tweak several views;
  * Don't expire contract when date is set to Today - they will be
    automatically expired the next day;
  * Show contract name on form view.

closes odoo/odoo#92604

Related: odoo/enterprise#27919
Taskid: 2856135
Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
Kevin Baptiste
2022-06-23 17:16:57 +02:00
parent 112abd5b91
commit 45b175a18d
11 changed files with 135 additions and 32 deletions
+11
View File
@@ -112,6 +112,17 @@ class FleetVehicle(models.Model):
frame_type = fields.Selection([('diamant', 'Diamant'), ('trapez', 'Trapez'), ('wave', 'Wave')], help="Frame type of the bike")
electric_assistance = fields.Boolean(compute='_compute_model_fields', store=True, readonly=False)
frame_size = fields.Float()
service_activity = fields.Selection([
('none', 'None'),
('overdue', 'Overdue'),
('today', 'Today'),
], compute='_compute_service_activity')
@api.depends('log_services')
def _compute_service_activity(self):
for vehicle in self:
activities_state = set(state for state in vehicle.log_services.mapped('activity_state') if state and state != 'planned')
vehicle.service_activity = sorted(activities_state)[0] if activities_state else 'none'
@api.depends('model_id')
def _compute_model_fields(self):
@@ -23,7 +23,7 @@ class FleetVehicleLogContract(models.Model):
date = fields.Date(help='Date when the cost has been executed')
company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company)
currency_id = fields.Many2one('res.currency', related='company_id.currency_id')
name = fields.Char(string='Name', compute='_compute_contract_name', store=True)
name = fields.Char(string='Name', compute='_compute_contract_name', store=True, readonly=False)
active = fields.Boolean(default=True)
user_id = fields.Many2one('res.users', 'Responsible', default=lambda self: self.env.user, index=True)
start_date = fields.Date(
@@ -34,6 +34,7 @@ class FleetVehicleLogContract(models.Model):
self.compute_next_year_date(fields.Date.context_today(self)),
help='Date when the coverage of the contract expirates (by default, one year after begin date)')
days_left = fields.Integer(compute='_compute_days_left', string='Warning Date')
expires_today = fields.Boolean(compute='_compute_days_left')
insurer_id = fields.Many2one('res.partner', 'Vendor')
purchaser_id = fields.Many2one(related='vehicle_id.driver_id', string='Driver')
ins_ref = fields.Char('Reference', size=64, copy=False)
@@ -72,14 +73,16 @@ class FleetVehicleLogContract(models.Model):
if contract is in a closed state, return -1
otherwise return the number of days before the contract expires
"""
today = fields.Date.from_string(fields.Date.today())
for record in self:
if record.expiration_date and record.state in ['open', 'expired']:
today = fields.Date.from_string(fields.Date.today())
renew_date = fields.Date.from_string(record.expiration_date)
diff_time = (renew_date - today).days
record.days_left = diff_time if diff_time > 0 else 0
record.expires_today = diff_time == 0
else:
record.days_left = -1
record.expires_today = False
def write(self, vals):
res = super(FleetVehicleLogContract, self).write(vals)
@@ -89,7 +92,7 @@ class FleetVehicleLogContract(models.Model):
for contract in self.filtered(lambda c: c.start_date and c.state != 'closed'):
if date_today < contract.start_date:
future_contracts |= contract
elif not contract.expiration_date or contract.start_date <= date_today < contract.expiration_date:
elif not contract.expiration_date or contract.start_date <= date_today <= contract.expiration_date:
running_contracts |= contract
else:
expired_contracts |= contract
@@ -13,6 +13,7 @@ class FleetVehicleLogServices(models.Model):
active = fields.Boolean(default=True)
vehicle_id = fields.Many2one('fleet.vehicle', 'Vehicle', required=True, help='Vehicle concerned by this log')
manager_id = fields.Many2one('res.users', 'Fleet Manager', related='vehicle_id.manager_id', store=True)
amount = fields.Monetary('Cost')
description = fields.Char('Description')
odometer_id = fields.Many2one('fleet.vehicle.odometer', 'Odometer', help='Odometer measure of the vehicle at the moment of this log')
@@ -43,7 +43,6 @@ class FleetVehicleModel(models.Model):
horsepower_tax = fields.Float('Horsepower Taxation')
electric_assistance = fields.Boolean(default=False)
@api.depends('name', 'brand_id')
def name_get(self):
res = []
for record in self:
@@ -9,16 +9,20 @@ class FleetVehicleModelBrand(models.Model):
_description = 'Brand of the vehicle'
_order = 'name asc'
name = fields.Char('Make', required=True)
name = fields.Char('Name', required=True)
image_128 = fields.Image("Logo", max_width=128, max_height=128)
model_count = fields.Integer(compute="_compute_model_count", string="", store=True)
model_ids = fields.One2many('fleet.vehicle.model', 'brand_id')
@api.depends('model_ids')
def _compute_model_count(self):
Model = self.env['fleet.vehicle.model']
model_data = self.env['fleet.vehicle.model']._read_group([
('brand_id', 'in', self.ids),
], ['brand_id'], ['brand_id'])
models_brand = {x['brand_id'][0]: x['brand_id_count'] for x in model_data}
for record in self:
record.model_count = Model.search_count([('brand_id', '=', record.id)])
record.model_count = models_brand.get(record.id, 0)
def action_brand_model(self):
self.ensure_one()
+1 -1
View File
@@ -9,6 +9,6 @@ class FleetVehicleTag(models.Model):
_description = 'Vehicle Tag'
name = fields.Char('Tag Name', required=True, translate=True)
color = fields.Integer('Color Index')
color = fields.Integer('Color')
_sql_constraints = [('name_uniq', 'unique (name)', "Tag name already exists !")]
@@ -0,0 +1,7 @@
.o_fleet_form {
.oe_stat_button.text-warning, .oe_stat_button.text-danger {
.o_stat_text {
color: $o-main-text-color;
}
}
}
@@ -8,7 +8,7 @@
<header>
<button name="action_open" states="futur" type="object" string="Start Contract" class="oe_highlight" groups="fleet.fleet_group_manager"/>
<button name="action_close" states="futur" type="object" string="Cancel" groups="fleet.fleet_group_manager"/>
<button name="action_close" states="open,expired,futur" type="object" class="oe_highlight" string="Close Contract" groups="fleet.fleet_group_manager"/>
<button name="action_close" states="open,expired,futur" type="object" string="Close Contract" groups="fleet.fleet_group_manager"/>
<button name="action_draft" states="closed" type="object" string="Reset To Draft" groups="fleet.fleet_group_manager"/>
<field name="state" widget="statusbar" />
</header>
@@ -68,11 +68,13 @@
<field name="model">fleet.vehicle.log.contract</field>
<field name="arch" type="xml">
<tree string="Contract logs"
decoration-danger="days_left==0"
decoration-warning="expires_today"
decoration-danger="days_left==0 and not expires_today"
decoration-muted="state=='closed'"
default_order="expiration_date"
sample="1">
<field name="active" invisible="1"/>
<field name="expires_today" invisible="1"/>
<field name="name" class="font-weight-bold" />
<field name="start_date" />
<field name="expiration_date" widget="remaining_days"/>
@@ -257,7 +259,7 @@
<field name="name">fleet.vehicle.log.services.tree</field>
<field name="model">fleet.vehicle.log.services</field>
<field name="arch" type="xml">
<tree string="Services Logs" multi_edit="1">
<tree string="Services Logs" multi_edit="1" expand="1">
<field name="date" readonly="1" />
<field name="description" />
<field name="service_type_id" />
@@ -340,6 +342,25 @@
</field>
</record>
<record id="fleet_vehicle_log_services_view_activity" model="ir.ui.view">
<field name="model">fleet.vehicle.log.services</field>
<field name="arch" type="xml">
<activity string="Services">
<templates>
<div t-name="activity-box">
<img t-att-src="activity_image('fleet.vehicle', 'image_128', record.vehicle_id.raw_value)" role="img" t-att-title="record.vehicle_id.value" t-att-alt="record.vehicle_id.value"/>
<div>
<field name="vehicle_id"/>
<t t-if="record.description.raw_value">
: <field name="description"/>
</t>
</div>
</div>
</templates>
</activity>
</field>
</record>
<record id="fleet_vehicle_log_services_view_pivot" model="ir.ui.view">
<field name="model">fleet.vehicle.log.services</field>
<field name="arch" type="xml">
@@ -362,6 +383,10 @@
<field name="service_type_id"/>
<separator/>
<filter string="Archived" name="inactive" domain="[('active', '=', False)]"/>
<group expand="1" string="Group By">
<filter string="Service Type" name="groupby_service_type_id" context="{'group_by': 'service_type_id'}"/>
<filter string="Fleet Manager" name="groupby_manager_id" context="{'group_by': 'manager_id'}"/>
</group>
</search>
</field>
</record>
@@ -369,7 +394,8 @@
<record id='fleet_vehicle_log_services_action' model='ir.actions.act_window'>
<field name="name">Services</field>
<field name="res_model">fleet.vehicle.log.services</field>
<field name="view_mode">tree,kanban,form,graph,pivot</field>
<field name="view_mode">tree,kanban,form,graph,pivot,activity</field>
<field name="context">{'search_default_groupby_service_type_id': 1}</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create a new service entry
@@ -143,7 +143,7 @@
</record>
<record id='fleet_vehicle_model_action' model='ir.actions.act_window'>
<field name="name">Vehicle Models</field>
<field name="name">Models</field>
<field name="res_model">fleet.vehicle.model</field>
<field name="view_mode">tree,form</field>
<field name="context">{"search_default_groupby_brand" : True,}</field>
@@ -165,6 +165,7 @@
<field name="arch" type="xml">
<tree string="Model Make">
<field name="name" />
<field name="model_count" string="Models"/>
</tree>
</field>
</record>
@@ -209,7 +210,7 @@
<span class="fa fa-ellipsis-v"/>
</a>
<div class="dropdown-menu" role="menu">
<a role="menuitem" type="open" class="dropdown-item">Properties</a>
<a role="menuitem" type="open" class="dropdown-item">Configuration</a>
</div>
</div>
<div class="o_kanban_image">
@@ -257,7 +258,7 @@
<!-- Model Category -->
<record id='fleet_vehicle_model_category_action' model='ir.actions.act_window'>
<field name="name">Model Category</field>
<field name="name">Categories</field>
<field name="res_model">fleet.vehicle.model.category</field>
<field name="view_mode">tree</field>
<field name="help" type="xml">
@@ -297,7 +298,8 @@
</field>
</record>
<menuitem action="fleet_vehicle_model_brand_action" parent="fleet_configuration" id="fleet_vehicle_model_brand_menu" sequence="2"/>
<menuitem action="fleet_vehicle_model_action" parent="fleet_configuration" id="fleet_vehicle_model_menu" sequence="2"/>
<menuitem action="fleet_vehicle_model_category_action" parent="fleet_configuration" id="fleet_vehicle_model_category_menu" sequence="2"/>
<menuitem name="Models" parent="fleet_configuration" id="fleet_models_configuration" sequence="10" groups="fleet_group_manager"/>
<menuitem action="fleet_vehicle_model_brand_action" parent="fleet_models_configuration" id="fleet_vehicle_model_brand_menu" sequence="1"/>
<menuitem action="fleet_vehicle_model_action" parent="fleet_models_configuration" id="fleet_vehicle_model_menu" sequence="5"/>
<menuitem action="fleet_vehicle_model_category_action" parent="fleet_models_configuration" id="fleet_vehicle_model_category_menu" sequence="10"/>
</odoo>
+50 -13
View File
@@ -5,7 +5,8 @@
<field name="name">fleet.vehicle.form</field>
<field name="model">fleet.vehicle</field>
<field name="arch" type="xml">
<form string="Vehicle" js_class="fleet_form">
<form string="Vehicle" js_class="fleet_form" class="o_fleet_form">
<field name="service_activity" invisible="1"/>
<header>
<button string="Apply New Driver"
class="btn btn-primary"
@@ -37,7 +38,26 @@
class="oe_stat_button"
icon="fa-wrench"
context="{'xml_id':'fleet_vehicle_log_services_action', 'search_default_inactive': not active}"
help="show the services logs for this vehicle" >
attrs="{'invisible': [('service_activity', '!=', 'none')]}"
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 text-danger"
icon="fa-wrench"
context="{'xml_id':'fleet_vehicle_log_services_action', 'search_default_inactive': not active}"
attrs="{'invisible': [('service_activity', '!=', 'overdue')]}"
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 text-warning"
icon="fa-wrench"
context="{'xml_id':'fleet_vehicle_log_services_action', 'search_default_inactive': not active}"
attrs="{'invisible': [('service_activity', '!=', 'today')]}"
help="show the services logs for this vehicle">
<field name="service_count" widget="statinfo" string="Services"/>
</button>
<button name="return_action_to_open"
@@ -162,8 +182,8 @@
<field name="model_id" widget="many2one_avatar" readonly="1"/>
<field name="category_id"/>
<field name="manager_id" optional="hide"/>
<field name="driver_id" widget="many2one_avatar" readonly="1"/>
<field name="future_driver_id" widget="many2one_avatar" readonly="1"/>
<field name="driver_id" widget="many2one_avatar" readonly="1" optional="show"/>
<field name="future_driver_id" widget="many2one_avatar" readonly="1" optional="show"/>
<field name="log_drivers" invisible="1"/>
<field name="vin_sn" readonly="1" optional="hide"/>
<field name="co2" string="CO2 Emissions g/km" optional="hide" readonly="1"/>
@@ -262,7 +282,7 @@
<t t-if="record.future_driver_id.raw_value">Future Driver : <field name="future_driver_id"/></t>
</li>
<li>
<t t-if="record.location.raw_value"><field name="location"/></t>
<t t-if="record.location.raw_value"><small><i class="fa fa-map-marker" title="Location"></i> <field name="location"/></small></t>
</li>
</ul>
<div class="o_kanban_record_bottom" t-if="!selection_mode">
@@ -316,7 +336,7 @@
<field name="state_id" type="col" />
<field name="brand_id" type="row" />
<field name="model_id" type="row" />
<field name="name" type="row" />
<field name="license_plate" type="row" />
</pivot>
</field>
</record>
@@ -446,15 +466,28 @@
<field name="name">fleet.service.type.tree</field>
<field name="model">fleet.service.type</field>
<field name="arch" type="xml">
<tree string="Service Types">
<tree string="Service Types" editable="bottom">
<field name="name" />
<field name="category"/>
</tree>
</field>
</record>
<record id="fleet_vehicle_service_types_view_search" model="ir.ui.view">
<field name="model">fleet.service.type</field>
<field name="arch" type="xml">
<search>
<field name="name"/>
<field name="category"/>
<group expand="1" string="Group By">
<filter name="groupby_category" context="{'group_by' : 'category'}"/>
</group>
</search>
</field>
</record>
<record id='fleet_vehicle_service_types_action' model='ir.actions.act_window'>
<field name="name">Service Types</field>
<field name="name">Types</field>
<field name="res_model">fleet.service.type</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
@@ -465,7 +498,9 @@
</p>
</field>
</record>
<menuitem action="fleet_vehicle_service_types_action" parent="fleet_configuration" id="fleet_vehicle_service_types_menu" sequence="3" groups="base.group_no_one"/>
<menuitem name="Services" parent="fleet_configuration" id="fleet_services_configuration" sequence="20" groups="base.group_no_one"/>
<menuitem action="fleet_vehicle_service_types_action" parent="fleet_services_configuration" name="Types"
id="fleet_vehicle_service_types_menu" sequence="1" groups="base.group_no_one"/>
<record id='fleet_vehicle_state_view_tree' model='ir.ui.view'>
<field name="name">fleet.vehicle.state.tree</field>
@@ -479,7 +514,7 @@
</record>
<record id='fleet_vehicle_state_action' model='ir.actions.act_window'>
<field name="name">Vehicle Status</field>
<field name="name">Status</field>
<field name="res_model">fleet.vehicle.state</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
@@ -492,7 +527,8 @@
</field>
</record>
<menuitem action="fleet_vehicle_state_action" parent="fleet_configuration" id="fleet_vehicle_state_menu" groups="base.group_no_one"/>
<menuitem name="Vehicle" parent="fleet_configuration" id="fleet_vehicles_configuration" sequence="30" groups="base.group_no_one"/>
<menuitem action="fleet_vehicle_state_action" parent="fleet_vehicles_configuration" id="fleet_vehicle_state_menu" sequence="10" groups="base.group_no_one"/>
<record id="fleet_vehicle_tag_view_view_form" model="ir.ui.view">
<field name="name">fleet.vehicle.tag.form</field>
@@ -514,12 +550,13 @@
<field name="arch" type="xml">
<tree string="Vehicle Tags" editable="bottom">
<field name="name"/>
<field name="color" widget="color_picker"/>
</tree>
</field>
</record>
<record id="fleet_vehicle_tag_action" model="ir.actions.act_window">
<field name="name">Vehicle Tags</field>
<field name="name">Tags</field>
<field name="res_model">fleet.vehicle.tag</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
@@ -528,7 +565,7 @@
</field>
</record>
<menuitem id="fleet_vehicle_tag_menu" parent="fleet_configuration" action="fleet_vehicle_tag_action" sequence="89" groups="base.group_no_one"/>
<menuitem id="fleet_vehicle_tag_menu" parent="fleet_vehicles_configuration" action="fleet_vehicle_tag_action" sequence="20" groups="base.group_no_one"/>
<record id="fleet_vehicle_assignation_log_view_list" model="ir.ui.view">
<field name="name">fleet.vehicle.assignation.log.view.tree</field>
+14 -1
View File
@@ -62,7 +62,7 @@
<button name="open_assignation_logs" position="before">
<button name="action_open_employee" type="object" class="oe_stat_button" icon="fa-id-card-o" groups="hr.group_hr_user" attrs="{'invisible': [('driver_employee_id', '=', False)]}">
<div class="o_field_widget o_stat_info">
<span class="o_stat_value"><field name="driver_employee_name"/></span>
<span class="o_stat_value">1</span>
<span class="o_stat_text">Employee</span>
</div>
</button>
@@ -83,6 +83,19 @@
</field>
</record>
<record id="fleet_vehicle_view_tree_inherit_hr" model="ir.ui.view">
<field name="model">fleet.vehicle</field>
<field name="inherit_id" ref="fleet.fleet_vehicle_view_tree"/>
<field name="arch" type="xml">
<field name="driver_id" position="after">
<field name="driver_employee_id" optional="hide"/>
</field>
<field name="future_driver_id" position="after">
<field name="future_driver_employee_id" optional="hide"/>
</field>
</field>
</record>
<record id="view_attachment_kanban_inherit_hr" model="ir.ui.view">
<field name="name">ir.attachment.kanban.inherit.hr</field>
<field name="model">ir.attachment</field>