From aa9642215a1b47fd4c8ddf85be487a6a8d5ba0f2 Mon Sep 17 00:00:00 2001 From: paso-odoo Date: Tue, 20 Jun 2023 05:38:35 +0000 Subject: [PATCH] [FIX] hr: launch plan for archived employees Issue 1 ======= When an employee is archived and the user clicks on the 'Launch Plan' button from that employee, it will throw an IndexError saying the tuple index is out of range. Steps to produce: - Open any Employee > Action > Archive > Apply. - Open archived employee(s) from the Filters > Archived. - From list view or form view, Click on the 'Launch Plan' button. - Error: IndexError: tuple index out of range. Fixed this issue using the current company if the employee and their company are not found. Issue 2 ======= When a user clicks on the 'Launch Plan' button from that employee, It will throw an IndexError saying the tuple index is out of range. Steps to produce: - Open any Employee. - Make the 'name' field unrequired (Studio or Edit form view). - Now create a new employee - before clicking on the Save button click on the 'Launch Plan' button. - Discard Changes > Error will produce. Fixed this issue using the check before using the employee record. sentry-4259555464 closes odoo/odoo#128138 X-original-commit: 7ebe9dcdbe80f8309a82521986437b512ce656c4 Signed-off-by: Sofie Gvaladze (sgv) Signed-off-by: Parth Solanki (paso) --- addons/hr/wizard/hr_plan_wizard.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/hr/wizard/hr_plan_wizard.py b/addons/hr/wizard/hr_plan_wizard.py index e62a5992a85..af80aef2018 100644 --- a/addons/hr/wizard/hr_plan_wizard.py +++ b/addons/hr/wizard/hr_plan_wizard.py @@ -14,6 +14,8 @@ class HrPlanWizard(models.TransientModel): def _default_plan_id(self): # We know that all employees belong to the same company employees = self.env['hr.employee'].browse(self.env.context.get('active_ids') if self.env.context.get('active_ids') else []) + if not employees: + return None if len(employees.department_id) > 1: return self.env['hr.plan'].search([ ('company_id', '=', employees[0].company_id.id), @@ -53,7 +55,7 @@ class HrPlanWizard(models.TransientModel): @api.depends('employee_ids') def _compute_company_id(self): for wizard in self: - wizard.company_id = wizard.employee_ids[0].company_id + wizard.company_id = wizard.employee_ids and wizard.employee_ids[0].company_id or self.env.company def _get_warnings(self): self.ensure_one()