From 5ffbcd57ae6474470c38e77c617fb94fd9102e2b Mon Sep 17 00:00:00 2001 From: Prakash Prajapati Date: Mon, 25 Nov 2019 04:55:33 +0000 Subject: [PATCH] [IMP] hr_contract: improve the contract general usability Purpose fo the task is to improve the usability of hr contract and automatic alert before contract expired -improve sign demo data -improve kanban state field in contract kanban -improve contract Form view ui -set first contract date on employee form -added the date of last completed contract on the new contract -improve signature request form -create automatic activity before the week of contract expired date closes odoo/odoo#40789 Task: 2049413 Closes: #40789 Related: odoo/enterprise#7454 Signed-off-by: Yannick Tivisse (yti) --- addons/hr_contract/models/hr_contract.py | 17 +++-- addons/hr_contract/models/hr_employee.py | 10 +++ .../hr_contract/views/hr_contract_views.xml | 71 ++++++++++++------- 3 files changed, 66 insertions(+), 32 deletions(-) diff --git a/addons/hr_contract/models/hr_contract.py b/addons/hr_contract/models/hr_contract.py index b3b59023949..345fb5fe016 100644 --- a/addons/hr_contract/models/hr_contract.py +++ b/addons/hr_contract/models/hr_contract.py @@ -58,6 +58,7 @@ class Contract(models.Model): hr_responsible_id = fields.Many2one('res.users', 'HR Responsible', tracking=True, help='Person responsible for validating the employee\'s contracts.') calendar_mismatch = fields.Boolean(compute='_compute_calendar_mismatch') + first_contract_date = fields.Date(related='employee_id.first_contract_date') @api.depends('employee_id.resource_calendar_id', 'resource_calendar_id') def _compute_calendar_mismatch(self): @@ -108,8 +109,8 @@ class Contract(models.Model): @api.model def update_state(self): - self.search([ - ('state', '=', 'open'), + contracts = self.search([ + ('state', '=', 'open'), ('kanban_state', '!=', 'blocked'), '|', '&', ('date_end', '<=', fields.Date.to_string(date.today() + relativedelta(days=7))), @@ -117,9 +118,15 @@ class Contract(models.Model): '&', ('visa_expire', '<=', fields.Date.to_string(date.today() + relativedelta(days=60))), ('visa_expire', '>=', fields.Date.to_string(date.today() + relativedelta(days=1))), - ]).write({ - 'kanban_state': 'blocked' - }) + ]) + + for contract in contracts: + contract.activity_schedule( + 'mail.mail_activity_data_todo', contract.date_end, + _("The contract of %s is about to expire.") % contract.employee_id.name, + user_id=contract.hr_responsible_id.id or self.env.uid) + + contracts.write({'kanban_state': 'blocked'}) self.search([ ('state', '=', 'open'), diff --git a/addons/hr_contract/models/hr_employee.py b/addons/hr_contract/models/hr_employee.py index 917b68d5054..8c4e900f97b 100644 --- a/addons/hr_contract/models/hr_employee.py +++ b/addons/hr_contract/models/hr_employee.py @@ -16,6 +16,16 @@ class Employee(models.Model): calendar_mismatch = fields.Boolean(related='contract_id.calendar_mismatch') contracts_count = fields.Integer(compute='_compute_contracts_count', string='Contract Count') contract_warning = fields.Boolean(string='Contract Warning', store=True, compute='_compute_contract_warning', groups="hr.group_hr_user") + first_contract_date = fields.Date(compute='_compute_first_contract_date', groups="hr.group_hr_user") + + @api.depends('contract_ids.state') + def _compute_first_contract_date(self): + for employee in self: + contracts = employee.contract_ids.filtered(lambda c: c.state != 'cancel') + if contracts: + employee.first_contract_date = min(contracts.mapped('date_start')) + else: + employee.first_contract_date = False @api.depends('contract_id', 'contract_id.state', 'contract_id.kanban_state') def _compute_contract_warning(self): diff --git a/addons/hr_contract/views/hr_contract_views.xml b/addons/hr_contract/views/hr_contract_views.xml index ab341a8fb1e..ba2437cf666 100644 --- a/addons/hr_contract/views/hr_contract_views.xml +++ b/addons/hr_contract/views/hr_contract_views.xml @@ -19,14 +19,37 @@
+
+ + + @@ -140,37 +163,29 @@ + + - - + + + + + - - - - - @@ -246,7 +261,6 @@
- @@ -256,6 +270,9 @@
+ + +