Files
odoo_source/addons/hr/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

39 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class HrDepartureWizard(models.TransientModel):
_name = 'hr.departure.wizard'
_description = 'Departure Wizard'
def _get_default_departure_date(self):
departure_date = False
if self.env.context.get('active_id'):
departure_date = self.env['hr.employee'].browse(self.env.context['active_id']).departure_date
return departure_date or fields.Date.today()
departure_reason_id = fields.Many2one("hr.departure.reason", default=lambda self: self.env['hr.departure.reason'].search([], limit=1), required=True)
departure_description = fields.Html(string="Additional Information")
departure_date = fields.Date(string="Departure Date", required=True, default=_get_default_departure_date)
employee_id = fields.Many2one(
'hr.employee', string='Employee', required=True,
default=lambda self: self.env.context.get('active_id', None),
)
archive_private_address = fields.Boolean('Archive Private Address', default=True)
def action_register_departure(self):
employee = self.employee_id
if self.env.context.get('toggle_active', False) and employee.active:
employee.with_context(no_wizard=True).toggle_active()
employee.departure_reason_id = self.departure_reason_id
employee.departure_description = self.departure_description
employee.departure_date = self.departure_date
if self.archive_private_address:
# ignore contact links to internal users
private_address = employee.address_home_id
if private_address and private_address.active and not self.env['res.users'].search([('partner_id', '=', private_address.id)]):
private_address.sudo().toggle_active()