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>
28 lines
1.3 KiB
Python
28 lines
1.3 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=True)
|
|
|
|
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})
|