From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/hr_contract/wizard/__init__.py | 4 ++++ addons/hr_contract/wizard/hr_departure_wizard.py | 24 ++++++++++++++++++++++ .../wizard/hr_departure_wizard_views.xml | 16 +++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 addons/hr_contract/wizard/__init__.py create mode 100644 addons/hr_contract/wizard/hr_departure_wizard.py create mode 100644 addons/hr_contract/wizard/hr_departure_wizard_views.xml (limited to 'addons/hr_contract/wizard') 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 @@ + + + + hr.departure.wizard.view.form.extend + hr.departure.wizard + + + + + + + + + + + -- cgit v1.2.3