Files
odoo_source/addons/hr_fleet/wizard/hr_departure_wizard.py
T
sofiagvaladze 6106f2eb9a [FIX] hr_contract: fix access error when archiving employee
Scenario:
hr_contract is installed and employee/officer without rights on contract
tries to archive an employee.

Before the fix:
An employee/officer without rights on contract gets the following access error:
Due to security restrictions, you are not allowed to access 'Employee Contract' (hr.contract) records.
THis is because the action tries to access employee's contract and set
date_end on it.

After the fix an employee/officer without rights on contract can archive
an employee without access error.

task - 2811165

closes odoo/odoo#98648

X-original-commit: c7ff577053a120f8f961642891d3a0ec0c960ae8
Signed-off-by: Kevin Baptiste <kba@odoo.com>
2022-08-23 16:29:29 +02:00

28 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class HrDepartureWizard(models.TransientModel):
_inherit = 'hr.departure.wizard'
release_campany_car = fields.Boolean("Release Company Car", default=lambda self: self.env.user.user_has_groups('fleet.fleet_group_user'))
def action_register_departure(self):
super(HrDepartureWizard, self).action_register_departure()
if self.release_campany_car:
self._free_campany_car()
def _free_campany_car(self):
"""Find all fleet.vehichle.assignation.log records that link to the employee, if there is no
end date or end date > departure date, update the date. Also check fleet.vehicle to see if
there is any record with its dirver_id to be the employee, set them to False."""
drivers = self.employee_id.user_id.partner_id | self.employee_id.sudo().address_home_id
assignations = self.env['fleet.vehicle.assignation.log'].search([('driver_id', 'in', drivers.ids)])
for assignation in assignations:
if self.departure_date and (not assignation.date_end or assignation.date_end > self.departure_date):
assignation.write({'date_end': self.departure_date})
cars = self.env['fleet.vehicle'].search([('driver_id', 'in', drivers.ids)])
cars.write({'driver_id': False, 'driver_employee_id': False})