summaryrefslogtreecommitdiff
path: root/addons/hr_contract
diff options
context:
space:
mode:
authoryhu-odoo <yhu@odoo.com>2019-12-26 15:35:26 +0000
committerYannick Tivisse <yti@odoo.com>2020-01-29 10:05:12 +0000
commit32fc38ef58dc4b4f1ff4e176ff4fa03b9c427397 (patch)
tree0c1b87a8b507e0710c75f12e3632bcc54b599f21 /addons/hr_contract
parent79ce907f664b63576a212a9e5652ce129210b6b5 (diff)
[IMP] hr_appraisal: Improve employee archiving flow
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>
Diffstat (limited to 'addons/hr_contract')
-rw-r--r--addons/hr_contract/__init__.py1
-rw-r--r--addons/hr_contract/__manifest__.py1
-rw-r--r--addons/hr_contract/wizard/__init__.py4
-rw-r--r--addons/hr_contract/wizard/hr_departure_wizard.py24
-rw-r--r--addons/hr_contract/wizard/hr_departure_wizard_views.xml16
5 files changed, 46 insertions, 0 deletions
diff --git a/addons/hr_contract/__init__.py b/addons/hr_contract/__init__.py
index dc5e6b693d1..2ae6446f9dc 100644
--- a/addons/hr_contract/__init__.py
+++ b/addons/hr_contract/__init__.py
@@ -2,3 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
+from . import wizard
diff --git a/addons/hr_contract/__manifest__.py b/addons/hr_contract/__manifest__.py
index f05b650c937..c3df359512d 100644
--- a/addons/hr_contract/__manifest__.py
+++ b/addons/hr_contract/__manifest__.py
@@ -24,6 +24,7 @@ You can assign several contracts per employee.
'data/hr_contract_data.xml',
'views/hr_contract_views.xml',
'views/assets.xml',
+ 'wizard/hr_departure_wizard_views.xml',
],
'demo': ['data/hr_contract_demo.xml'],
'installable': True,
diff --git a/addons/hr_contract/wizard/__init__.py b/addons/hr_contract/wizard/__init__.py
new file mode 100644
index 00000000000..ea671ff9df8
--- /dev/null
+++ b/addons/hr_contract/wizard/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import hr_departure_wizard
diff --git a/addons/hr_contract/wizard/hr_departure_wizard.py b/addons/hr_contract/wizard/hr_departure_wizard.py
new file mode 100644
index 00000000000..84abad579a9
--- /dev/null
+++ b/addons/hr_contract/wizard/hr_departure_wizard.py
@@ -0,0 +1,24 @@
+# -*- 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=True)
+
+ 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.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.employee_id.contract_ids.filtered(lambda c: c.state == 'draft').write({'state': 'cancel'})
+ if current_contract:
+ self.employee_id.contract_id.write({'date_end': self.departure_date})
diff --git a/addons/hr_contract/wizard/hr_departure_wizard_views.xml b/addons/hr_contract/wizard/hr_departure_wizard_views.xml
new file mode 100644
index 00000000000..d336d93899e
--- /dev/null
+++ b/addons/hr_contract/wizard/hr_departure_wizard_views.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <record id="hr_departure_wizard_view_form" model="ir.ui.view">
+ <field name="name">hr.departure.wizard.view.form.extend</field>
+ <field name="model">hr.departure.wizard</field>
+ <field name="inherit_id" ref="hr.hr_departure_wizard_view_form" />
+ <field name="arch" type="xml">
+ <xpath expr="//field[@name='departure_date']" position="replace">
+ <field name="departure_date" string="Contract End Date"/>
+ </xpath>
+ <xpath expr="//group[@id='date']" position="inside">
+ <field name="set_date_end" string="Set end date to current contract"/>
+ </xpath>
+ </field>
+ </record>
+</odoo>