summaryrefslogtreecommitdiff
path: root/addons/hr_contract/wizard
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/hr_contract/wizard
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/hr_contract/wizard')
-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
3 files changed, 44 insertions, 0 deletions
diff --git a/addons/hr_contract/wizard/__init__.py b/addons/hr_contract/wizard/__init__.py
new file mode 100644
index 00000000..ea671ff9
--- /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 00000000..84abad57
--- /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 00000000..d336d938
--- /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>