Using domain to limit what is displayed

In the Invoicing / Accounting app there is an option to view sales invoices (note: in Community Edition the user needs to have “Full Accounting Features” enabled).

Invoicing (or Accounting) > Accounting > Sales

This displays posted sales transactions [from Model account.move.line] using two filters – defined in the context in the Windows Action:

There’s more information about this below, but we are interested in the two filters:

  1. Posted transactions search_default_posted
  2. Sales transactions search_default_sales

Note that these filters can be removed by a user, making it possible to see all transactions (e.g. bank, purchase). You might want to limit this menu option to sales transactions only, and not other journal types.

This can be done by amending the domain on the Windows Action. Let’s go through this step by step, first by understanding which domain to use and then updating 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 (for a quicker but slightly more complex approach check the Search View).

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

After we select the filter it is shown at the top of the screen (if you had created a new filter the details would be shown, but in this case we used an existing filter so we can only see the name):

Next we need to save this search

Give it a name and click on Save

It’s shown under “Favorites”

The next step is to 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 do this in Developer Mode by clicking 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'))]

This will not display ‘Sections’ and ‘Notes’ (in display type), But it does NOT limit the type of transaction, so we can add the domain from the Filter we created above. We’ll also simplify it by excluding any display type rather than the two specified. This is the domain:

["&",
     ["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.

It should be noted that (as standard) this menu option is only available to Accounting users, who have access to all journal types, so there isn’t any problem with how this is setup. But some organizations might want to have some users with access to sales transactions only.

Also, Sales users are already limited to sales and purchase transactions through a Record Rule. But, again, you might want to change this.

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}

There are six elements:

  1. You might think that 'journal_type':'sales' would only display sales journals, but that field is not on the Model being used here [account.move.line]
    • It is a field on account.invoice (which was used in earlier versions of Odoo for invoices, but which doesn’t exist in Odoo 13)
  2. Filter: group by move (defined in the Search View, see below)
  3. Filter: posted transactions
  4. Filter: sales transactions
  5. Group by Name [groupby]
  6. Expand the list (if this was not specified, users would have to click on a move to show all the transactions).

The three filters (and others) are defined in the corresponding search view.

This can be found by navigating to Settings / Technical / Views entering the Model name [account.move.line] and filtering on “Search View”

There are two Search Views for this model and we want the first one (the second is an Extension View):

The first filter has no domain, but uses context to group transactions by account:

<filter string="Journal Entry" name="group_by_move"
    domain="[]" context="{'group_by': 'account_id'}"/>

The second filter has a domain to select posted transactions:

<filter string="Posted" name="posted" 
    domain="[('move_id.state', '=', 'posted')]" 
    help="Posted Journal Items"/>

The third filter has a domain to select sales transactions and uses context to set a default (but as the Form View blocks creation of new transactions here this is not needed):

 <filter string="Sales" name="sales" 
    domain="[('move_id.journal_id.type', '=', 'sale')]"
    context="{'default_journal_type': 'sale'}"/>

Note that it might be quicker to check the domain by reviewing the Search View rather than than the method described above.

Leave a comment