Users with both "HR Officer" and "Contract Administrator" access should be able to archive employees even without Payroll access. closes odoo/odoo#102102 X-original-commit: 765a6ec16b0a3c1cd86f7fc217bfb795a788d9c6 Signed-off-by: Kevin Baptiste <kba@odoo.com>
26 lines
1.2 KiB
Python
26 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import fields, models, _
|
|
from odoo.exceptions import UserError
|
|
|
|
|
|
class HrDepartureWizard(models.TransientModel):
|
|
_inherit = 'hr.departure.wizard'
|
|
|
|
set_date_end = fields.Boolean(string="Set Contract End Date", default=lambda self: self.env.user.user_has_groups('hr_contract.group_hr_contract_manager'),
|
|
help="Set the end date on the current contract.")
|
|
|
|
def action_register_departure(self):
|
|
"""If set_date_end is checked, set the departure date as the end date to current running contract,
|
|
and cancel all draft contracts"""
|
|
current_contract = self.sudo().employee_id.contract_id
|
|
if current_contract and current_contract.date_start > self.departure_date:
|
|
raise UserError(_("Departure date can't be earlier than the start date of current contract."))
|
|
|
|
super(HrDepartureWizard, self).action_register_departure()
|
|
if self.set_date_end:
|
|
self.sudo().employee_id.contract_ids.filtered(lambda c: c.state == 'draft').write({'state': 'cancel'})
|
|
if current_contract:
|
|
self.sudo().employee_id.contract_id.write({'date_end': self.departure_date})
|