[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) <yti@odoo.com>
This commit is contained in:
Kamesh Patel
2020-09-16 11:25:54 +00:00
committed by Yannick Tivisse
parent 7bd9d1a31e
commit cb461b77cd
2 changed files with 14 additions and 1 deletions
+8
View File
@@ -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:
+6 -1
View File
@@ -566,9 +566,14 @@
<field name="arch" type="xml">
<form string="Expense Reports" class="o_expense_sheet">
<field name="can_reset" invisible="1"/>
<field name="can_approve" invisible="1"/>
<header>
<button name="action_submit_sheet" states="draft" string="Submit to Manager" type="object" class="oe_highlight o_expense_sheet_submit"/>
<button name="approve_expense_sheets" states="submit" string="Approve" type="object" groups="hr_expense.group_hr_expense_team_approver" class="oe_highlight o_expense_sheet_approve"/>
<button name="approve_expense_sheets"
string="Approve"
type="object"
attrs="{'invisible': ['|', ('can_approve', '=', False), ('state', '!=', 'submit')]}"
class="oe_highlight o_expense_sheet_approve"/>
<button name="action_sheet_move_create"
string="Post Journal Entries"
type="object"