Using domain to limit what is displayed

In the Invoicing / Accounting app there is an option to view sales invoices.

The path is: Invoicing (or Accounting) / Accounting / Sales

This has two filters:

  1. Posted transactions
  2. Sales transactions

Note that filters can be removed, so it’s possible to see all transactions. But you might want to limit it to sales transactions so that users with access to this menu option can’t see other journals (e.g. bank, purchase).

This can be done by amending the domain on the Windows Action

Domain

The easiest way to find out what domain to use is by creating a filter. This is very easy to do.

In this case, there is already a standard filter, so we can use that.

This is now shown at the top of the screen (if you had created a filter the details would be shown, but in this case we used a standard filter):

Next we need to save this search

Give it a name and click on Save

It’s shown under “Favorites”

For more information you can enable “developer mode“, navigate to Technical / User-defined Filters and view the filter you created.

Click on the “Sales” filter

Click on “Edit”

Now we can see the domain:

[["move_id.journal_id.type","=","sale"]]

Windows Action

The next step is to add this domain to the Windows Action.

You can click on the “bug” icon and “Edit Action”

or you can select from Settings / Technical / Windows Actions:

Both methods will take you to the Windows Action

Note that there is already a domain:

[('display_type', 'not in', ('line_section', 'line_note'))]

But it does NOT limit the type of transaction, so we can add the domain from the Filter we created above.

["&",
     ["move_id.journal_id.type","=","sale"],
     ["display_type","=",False]]

More information about domains

After making this change, the user cannot select any other types of journal from this menu option.

However, they may be able to view these other types from another menu option. So a Record Rule may be a more complete solution, but it also needs more testing because it affects the whole of Odoo. You can use the same domain.

Context

This is the Context for the Windows Action:

{'journal_type':'sales',
     'search_default_group_by_move': 1,
     'search_default_posted':1,
     'search_default_sales':1,
     'name_groupby':1,
     'expand': 1}

Question: what is 'journal_type':'sales' supposed to do?