PURPOSE
=======
When you close a payroll (employees), there are often a lot of document
linked. Archiving an employee should archive the contract, cancel future
leaves, archive the private address
Specification
=============
Add departure date (hr):
- Add a Date field to both hr.departure.wizard and hr.employee. In
the wizard, the field is required.
- In toggle_active() method in hr.employee, set departure_date to
false when unarchive the employee.
- If user has a current running contract, a user error will raise if
user enter a departure date earlier than the start date of the
contract.
Add checkbox to set a closing date on hr.contract (hr.contract):
- In the hr.departure.wizard, set the departure date to be the end
date of runing contract. Set the states of all draft contracts to
"cancel".
Add checkbox to free car (hr.fleet):
- In the hr.departure.wizard, set end_date to
fleet.vehicle.assignation.log, if there is no end_date or end_date >
departure_date
- Go through fleet.vehicle, find records with dirver_id to be the
employee, set it to False.
Add checkbox to archive private address (hr):
- when the private address not link to a internel user, set
employee.address_home_id.active to Flase
- unarchive it after the employee unarchived
Add checkbox to cancel future appraisals (hr.appraisal)
- find all appraisals link to the employee and state in
['new', 'pending'], set their state to 'cancel'.
Add checkbox to cancel future leaves (hr.holidays):
- only consider leaves are not in state ['refuse', 'cancel'],
find leaves with to_date > departure_date, set their state to
'cancel'.
PR #42526
Task 2153106
Related: odoo/enterprise#7471
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
40 lines
1.7 KiB
Python
40 lines
1.7 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):
|
|
_name = 'hr.departure.wizard'
|
|
_description = 'Departure Wizard'
|
|
|
|
@api.model
|
|
def default_get(self, fields):
|
|
res = super(HrDepartureWizard, self).default_get(fields)
|
|
if (not fields or 'employee_id' in fields) and 'employee_id' not in res:
|
|
if self.env.context.get('active_id'):
|
|
res['employee_id'] = self.env.context['active_id']
|
|
return res
|
|
|
|
departure_reason = fields.Selection([
|
|
('fired', 'Fired'),
|
|
('resigned', 'Resigned'),
|
|
('retired', 'Retired')
|
|
], string="Departure Reason", default="fired")
|
|
departure_description = fields.Text(string="Additional Information")
|
|
departure_date = fields.Date(string="Departure Date", required=True, default=fields.Date.today)
|
|
employee_id = fields.Many2one('hr.employee', string='Employee', required=True)
|
|
archive_private_address = fields.Boolean('Archive Private Address', default=True)
|
|
|
|
def action_register_departure(self):
|
|
employee = self.employee_id
|
|
employee.departure_reason = self.departure_reason
|
|
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.toggle_active()
|