From cb461b77cdb1744fcdbd32bf8b4578e71cc27b1c Mon Sep 17 00:00:00 2001 From: Kamesh Patel Date: Mon, 31 Aug 2020 07:19:40 +0000 Subject: [PATCH] [IMP] expense: hide approve button on expense reports PURPOSE user with the 'team approver' or the 'all approver' access right levels cannot approve his own expenses. However, the 'approve' button is still being displayed, which is confusing and misleading, and an ugly user error is thrown when the user tries to click on it SPECIFICATIONS Hide the 'approve' button on expense reports If the user has either the 'team approver' or 'all approver' access right levels and the employee_id set on the report is linked to the current user LINKS Task-2323982 closes odoo/odoo#56784 Signed-off-by: Yannick Tivisse (yti) --- addons/hr_expense/models/hr_expense.py | 8 ++++++++ addons/hr_expense/views/hr_expense_views.xml | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index 5ff2a65164f..07606eb5e4c 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -782,6 +782,7 @@ class HrExpenseSheet(models.Model): department_id = fields.Many2one('hr.department', compute='_compute_from_employee_id', store=True, readonly=False, copy=False, string='Department', states={'post': [('readonly', True)], 'done': [('readonly', True)]}) is_multiple_currency = fields.Boolean("Handle lines with different currencies", compute='_compute_is_multiple_currency') can_reset = fields.Boolean('Can Reset', compute='_compute_can_reset') + can_approve = fields.Boolean('Can Approve', compute='_compute_can_approve') _sql_constraints = [ ('journal_id_required_posted', "CHECK((state IN ('post', 'done') AND journal_id IS NOT NULL) OR (state NOT IN ('post', 'done')))", 'The journal must be set on posted expense'), @@ -822,6 +823,13 @@ class HrExpenseSheet(models.Model): for sheet in self: sheet.can_reset = is_expense_user if is_expense_user else sheet.employee_id.user_id == self.env.user + @api.depends_context('uid') + def _compute_can_approve(self): + is_approver = self.user_has_groups('hr_expense.group_hr_expense_team_approver, hr_expense.group_hr_expense_user') + is_manager = self.user_has_groups('hr_expense.group_hr_expense_manager') + for sheet in self: + sheet.can_approve = is_manager or (is_approver and sheet.employee_id.user_id != self.env.user) + @api.depends('employee_id') def _compute_from_employee_id(self): for sheet in self: diff --git a/addons/hr_expense/views/hr_expense_views.xml b/addons/hr_expense/views/hr_expense_views.xml index 8d93d79f21a..e003a92acfe 100644 --- a/addons/hr_expense/views/hr_expense_views.xml +++ b/addons/hr_expense/views/hr_expense_views.xml @@ -566,9 +566,14 @@
+