Changing access rights on a button

In Odoo, it’s common to have buttons at the top of the screen to carry out various actions. For example, in the Expenses module, the following buttons are displayed for approved expense claims:

Here there are two buttons:

  • Post Journal Entries
  • Refuse (an Expense Claim)

Only the Advisor (Manager) can post journal entries for expenses, but in many organizations it could make sense for the accountant to be able to do this. It’s fairly simple to make that change, either using Odoo Studio or through the “debug” option.

First, it helps to understand access controls. In Odoo Enterprise there are three roles for the Accounting app (from highest to lowest level of access):

Advisor (Manager)account.group_account_manager
Accountantaccount.group_account_user
Billingaccount.group_account_invoice

As standard in Odoo, each level inherits access from lower levels in the same application, so the Accountant can do everything that the Billing user can do, and the Advisor (Manager) can do everything that the Accountant and Billing users can do.

The change we want to make is to allow the Accountant [account.group_account_user] to be able to post journals for Expenses (this will still allow the Advisor to do it).

Odoo Studio.

  1. Enable Odoo Studio
  2. Click on the button “Post Journal Entries”
  3. The following panel is displayed:

From the dropdown you can select another role. In this example it will be “Accounting / Accountant” (see list of roles above).

Studio creates an Extension View like this:

XML

This is the XML that is generated:

<data>
  <xpath expr="//button[@name='action_sheet_move_create']" position="attributes">
    <attribute name="groups">account.group_account_user</attribute>
  </xpath>
</data>

Manually (without Odoo Studio)

If you don’t have Studio you could create the Extension View manually with the same XML. There are several steps, but all of them are quite straightforward.

Start by enabling developer mode and then click on the “debug” icon and select “Edit View: Form” from the dropdown:

The following screen is displayed:

Click on “Inherited Views”

Click on “Add a line”

The following fields are already filled with default values that you don’t need to change:

  1. View Type = Form
  2. Model = hr.expense.sheet
  3. Sequence = 16
  4. Inherited View = hr.expense.sheet.form
  5. View Inheritance mode = Extension View

You need to enter a name and the XML

The name can be anything that is meaningful

The XML needs to be the same as above

Now you need to save the Extension View and the following will be displayed

Click on “Save” again and close the window by clicking in the to right hand corner.

The change is now complete

Button

We can review the (standard) XML to understand something about the Button:

<button name="action_sheet_move_create" 
        string="Post Journal Entries"
        type="object" 
        groups="account.group_account_manager" 
        attrs="{'invisible': [('state', '!=', 'approve')]}" 
        class="oe_highlight o_expense_sheet_post"/>
  1. The button name is action_sheet_move_create (you can see that is referenced in the Extension View)
  2. The string is the text displayed on the button
  3. The type is “object”
  4. Authorization to the button is controlled by groups. This is optional (no control) or could contain a list of groups
  5. Various attributes can be specified. In this case, the button is only displayed if the Expenses are already approved.
  6. Finally the class is the Python code that will post the journal entry

Notes

The groups in Community Edition are different. There is no Advisor role, and the Billing Administrator is the Manager (who is authorized to post journals for Expenses), so this change would probably not be required.

Billing Administratoraccount.group_account_manager
Billingaccount.group_account_invoice

And, yes, although this is quite easy to change it would be better if it could be configured rather than either requiring Odoo Studio or the creation of an XML view!