Purpose
=======
When an employee leaves the company, the fleet manager must ask to the insurance company
a claim report for this employee. But in oddo, there is no easy way to have an history
of the drivers.
Specification
=============
1/ On the employee form, add a stat button: "x cars". The button shouldn't be displayed if the count = 0.
Make a bridge (auto_install: True in the manifest) depending on hr (hr.employee) and fleet (fleet.vehicle.assignation.log)
- Add a field employee_cars_count (computed) to count the amount of cars the employee drove.
- Add an method action_open_employee_cars, that return an action (ir.actions.act_window)
that open on the fleet.vehicle kanban filtered on cars the employee had driven.
2/ In this bridge module, add on the fleet.vehicle.assignation.logs a button (like in expense) to upload
documents about the car for a particular employee (PV, rapport d'assurance, blabla). On the employee
form view, add an action button (with groups fleet_manager) to print all the related documents
(all the attachements on the fleet.vehicle.assignation.logs for the employee).
closes odoo/odoo#28077
40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
|
|
from odoo import fields, models
|
|
|
|
class Employee(models.Model):
|
|
_inherit = 'hr.employee'
|
|
|
|
employee_cars_count = fields.Integer(compute="_compute_employee_cars_count", string="Cars", group="fleet_manager")
|
|
|
|
def action_open_employee_cars(self):
|
|
self.ensure_one()
|
|
cars = self.env['fleet.vehicle.assignation.log'].search([
|
|
('driver_id', '=', self.user_id.partner_id.id)]).mapped('vehicle_id')
|
|
|
|
return {
|
|
"type": "ir.actions.act_window",
|
|
"res_model": "fleet.vehicle",
|
|
"views": [[False, "kanban"], [False, "form"], [False, "tree"]],
|
|
"domain": [("id", "in", cars.ids)],
|
|
"name": "History Employee Cars",
|
|
}
|
|
|
|
def _compute_employee_cars_count(self):
|
|
driver_ids = self.mapped('user_id.partner_id').ids
|
|
fleet_data = self.env['fleet.vehicle.assignation.log'].read_group(
|
|
domain=[('driver_id', 'in', driver_ids)], fields=['driver_id'], groupby=['driver_id'])
|
|
mapped_data = dict([(m['driver_id'][0], m['driver_id_count']) for m in fleet_data])
|
|
for employee in self:
|
|
employee.employee_cars_count = mapped_data.get(employee.user_id.partner_id.id, 0)
|
|
|
|
def action_get_claim_report(self):
|
|
self.ensure_one()
|
|
return {
|
|
'name': 'Claim Report',
|
|
'type': 'ir.actions.act_url',
|
|
'url': '/fleet/print_claim_report/%(employee_id)s' % {'employee_id': self.id},
|
|
}
|