Skip to content
Snippets Groups Projects
Commit 55a48e34 authored by Yannick Tivisse's avatar Yannick Tivisse
Browse files

[FIX] hr_fleet: Make 'Claim Report' work for employee without users

If an employee is not linked to an user, the claim report feature won't work.

With this commit, the report can be printed base on the user's partner or
the private employee address.

closes odoo/odoo#30065
parent 671c45fb
No related branches found
No related tags found
No related merge requests found
......@@ -19,11 +19,11 @@ class HrFleet(Controller):
return request.not_found()
employee = request.env['hr.employee'].search([('id', '=', employee_id)], limit=1)
partner_id = employee.user_id.partner_id.id
if not employee or not partner_id:
partner_ids = (employee.user_id.partner_id | employee.address_home_id).ids
if not employee or not partner_ids:
return request.not_found()
car_assignation_logs = request.env['fleet.vehicle.assignation.log'].search([('driver_id', '=', partner_id)])
car_assignation_logs = request.env['fleet.vehicle.assignation.log'].search([('driver_id', 'in', partner_ids)])
doc_list = request.env['ir.attachment'].search([
('res_model', '=', 'fleet.vehicle.assignation.log'),
('res_id', 'in', car_assignation_logs.ids)], order='create_date')
......
......@@ -12,7 +12,7 @@ class Employee(models.Model):
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')
('driver_id', 'in', (self.user_id.partner_id | self.address_home_id).ids)]).mapped('vehicle_id')
return {
"type": "ir.actions.act_window",
......@@ -23,12 +23,12 @@ class Employee(models.Model):
}
def _compute_employee_cars_count(self):
driver_ids = self.mapped('user_id.partner_id').ids
driver_ids = (self.mapped('user_id.partner_id') | self.mapped('address_home_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)
employee.employee_cars_count = mapped_data.get(employee.user_id.partner_id.id, 0) + mapped_data.get(employee.address_home_id.id, 0)
def action_get_claim_report(self):
self.ensure_one()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment