Making a field invisible

Here’s a simple example of using an Extension View to make a field invisible. The field is the Invoice Date on the Customer Invoice or Supplier Invoice (Vendor Bill).

Odoo 13 CE

The first thing to do is to get the field information. Enable developer mode and then hover your mouse over the field. A pop-up should show you the information you need.

So we know that the field name is invoice_date

The simplest way to create an Extension View is to click on the “bug” icon in the menu bar and select Edit View: Form

Click on “Inherited Views” and a list will be displayed. Click on “add a line”

(the list of inherited views will vary depending upon which modules are installed)

After clicking on “Add a line” the following will be displayed.

Helpfully, a lot of the information has already been defaulted

View Name:
View Type: Form
Model: account.move
Inherited View: account.move.form
View inheritance mode: Extension View

You need to give it a name and enter some XML in the Architecture tab (see below). It should then look like this:

Architecture

<data>
   <xpath expr="//field[@name='invoice_date']" position="attributes">
     <attribute name="groups">account.group_account_manager</attribute>
   </xpath>
</data>

Extension views always start with a <data> tag and end with a </data> tag

Then there will be at least one <xpath> expression. This identifies what is being amended (or where to add something). In this case we are amending the attributes for the field invoice_date and limiting access to one access group.

Note: the Invoicing / Accounting app in Odoo 13 CE has two roles:

  1. Billing [account.group_account_invoice]
  2. Billing Manager [account.group_account_manager]

The “Billing” role is the more junior, and so we will only allow the Manager to view the invoice date.

Save the Extension View and then refresh the screen in your browser.

There is a small problem with this. Hiding the field doesn’t hide the label:

That’s because the label depends upon the type of invoice, but that’s a problem for another day!

Odoo 13 Enterprise Edition

The database structure is the same, but the user access groups are different:

  1. Billing [account.group_account_invoice]
  2. Accountant [account.group_account_user]
  3. Advisor [account.group_account_manager]

This requires a small change to the XML (assuming that we want the Accountant to be able to edit invoice dates)

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

Odoo Studio

It’s also possible to make this change by using Odoo Studio

Enable Odoo Studio and click on the Invoice Date field

This will create an Extension View (exactly the same result as the steps above for CE)

Odoo 12 EE

The Model and Field names are different (there was a big change in Odoo 13), but the user access groups are the same.

This is the Extension View

Architecture

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

Apart from the field name, the XML is the same as in Odoo 13

Leave a comment