[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) <sgv@odoo.com>
Signed-off-by: Parth Solanki (paso) <paso@odoo.com>
This commit is contained in:
paso-odoo
2023-07-12 11:20:02 +02:00
parent 88b2e4f669
commit aa9642215a
+3 -1
View File
@@ -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()