From f77840cfc72e3a641ae41ec119c46672a32e4aee Mon Sep 17 00:00:00 2001 From: Philippe Wauthy Date: Fri, 5 Aug 2022 13:01:56 +0000 Subject: [PATCH] [IMP] hr(_holidays): improve department filters In the Employees app, when using the department kanban view and clicking on the Time Off Requests or Allocation Requests, it leads to a tree view but the department from which the user comes from is not part of the filters. This commit adds the department in the filters of the tree view. Due to the search panel being present in the tree view, the department filter is removed from the list of filters to avoid a duplication of the filters in the search panel. task-2939207 closes odoo/odoo#97773 Related: odoo/enterprise#30358 Signed-off-by: Kevin Baptiste --- addons/hr/views/hr_employee_views.xml | 1 - addons/hr_expense/models/hr_expense.py | 2 +- addons/hr_holidays/models/hr_department.py | 24 +++++++++++++++++++ .../views/hr_leave_allocation_views.xml | 1 - addons/hr_holidays/views/hr_leave_views.xml | 1 - addons/hr_holidays/views/hr_views.xml | 6 ++--- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/addons/hr/views/hr_employee_views.xml b/addons/hr/views/hr_employee_views.xml index a3e977df1e6..f614a37a749 100644 --- a/addons/hr/views/hr_employee_views.xml +++ b/addons/hr/views/hr_employee_views.xml @@ -10,7 +10,6 @@ - diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index 3487c9c7b30..a39efa59ab9 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -941,7 +941,7 @@ class HrExpenseSheet(models.Model): for sheet in self: sheet.expense_number = result.get(sheet.id, 0) - @api.depends('employee_id') + @api.depends('employee_id', 'employee_id.department_id') def _compute_from_employee_id(self): for sheet in self: sheet.address_id = sheet.employee_id.sudo().address_home_id diff --git a/addons/hr_holidays/models/hr_department.py b/addons/hr_holidays/models/hr_department.py index d3499f6cc48..b08dbee9b40 100644 --- a/addons/hr_holidays/models/hr_department.py +++ b/addons/hr_holidays/models/hr_department.py @@ -46,3 +46,27 @@ class Department(models.Model): department.leave_to_approve_count = res_leave.get(department.id, 0) department.allocation_to_approve_count = res_allocation.get(department.id, 0) department.absence_of_today = res_absence.get(department.id, 0) + + def _get_action_context(self): + return { + 'search_default_approve': 1, + 'search_default_active_employee': 2, + 'search_default_department_id': self.id, + 'default_department_id': self.id, + } + + def action_open_leave_department(self): + action = self.env["ir.actions.actions"]._for_xml_id("hr_holidays.hr_leave_action_action_approve_department") + action['context'] = { + **self._get_action_context(), + 'search_default_active_time_off': 3, + 'hide_employee_name': 1, + 'holiday_status_name_get': False + } + return action + + def action_open_allocation_department(self): + action = self.env["ir.actions.actions"]._for_xml_id("hr_holidays.hr_leave_allocation_action_approve_department") + action['context'] = self._get_action_context() + action['context']['search_default_second_approval'] = 3 + return action diff --git a/addons/hr_holidays/views/hr_leave_allocation_views.xml b/addons/hr_holidays/views/hr_leave_allocation_views.xml index 1cfeb827dc3..7254e35e9bb 100644 --- a/addons/hr_holidays/views/hr_leave_allocation_views.xml +++ b/addons/hr_holidays/views/hr_leave_allocation_views.xml @@ -31,7 +31,6 @@ - - diff --git a/addons/hr_holidays/views/hr_views.xml b/addons/hr_holidays/views/hr_views.xml index a41d5673726..7f1066a6734 100644 --- a/addons/hr_holidays/views/hr_views.xml +++ b/addons/hr_holidays/views/hr_views.xml @@ -7,7 +7,7 @@ kanban,tree,form { 'search_default_is_absent': 1, - 'searchpanel_default_department_id': active_id, + 'search_default_department_id': active_id, 'default_department_id': active_id} @@ -33,14 +33,14 @@