Filters

Odoo has different types of filter:

The first type of Filter is defined in a Search View and shown in the ‘Filters’ dropdown (blue box above with 9 filters, as explained below).

User-defined filters are shown under “Favourites” in the green box above, and in this example one has been setup (‘No customer’). More information here.

This article is about the first type of filter and the Search View that defines them [note that Odoo Studio makes it easy to add them, as explained here.]

Start by enabling developer mode and navigate to Settings / Technical / Views

We’ll use filters to find the Search View.

  • We need to know which Model (database table):
    • Maybe you already know that this is crm.lead
    • If not, you can find it in the address bar:
    • You could use the debug menu and check the Kanban View
  • The view type is “Search”

This is the list based on those filters:

The first Search View is for Opportunities, so that is the one we need (the second one is for Leads, the third one is for a report). If you aren’t sure which one to select, check them to see if they match what you can see in the ‘Filters’ dropdown.

The first part of this Search View defines the fields that are available in the search bar:

  1. Name field with “Opportunity” as the description
  2. Partner field with “Customer” as the description
  3. Tags
  4. Sales Team
  5. Stage
  6. Country
  7. City

The next section defines the filters (and the final section, not shown here, defines the ‘Group By’ options).

There are 12 filters defined, but 3 of them are invisible – and so there are 9 filters displayed:

  1. My Pipeline
  2. Unassigned
  3. Open Opportunities
  4. Unread Messages
  5. Creation Date
  6. Closed Date
  7. Won
  8. Lost
  9. Archived

Let’s take a look at the definition for the first filter:

My pipeline

<filter string="My Pipeline" name="assigned_to_me"

domain="[('user_id', '=', uid)]"

help="Opportunities that are assigned to me"

/>

  1. This starts with filter
  2. String is what is shown in the dropdown list (“My Pipeline”)
  3. Name is important because it allows this filter to be used elsewhere (e.g. in context for the Windows Action)
  4. Domain is where we define what is going to be selected (see below)
  5. Help text is optional
Domain

It’s important to understand the domain. In this example we are comparing the user ID on the record with the environment variable for the current user ID:

[('user_id', '=', uid)]

The second filter has a slightly different domain: [('user_id', '=', False)] to select Opportunities without a user assigned.

The third filter is to show “Open” opportunities:

[('probability', '<', 100), ('type', '=', 'opportunity')]

Odoo defines “open” as a percentage of less than 100% (because when it is set to ‘Won’ it becomes 100%).

There’s another filter for “Won” opportunities:

['&', ('active', '=', True), ('stage_id.is_won', '=', True)]

This is a little more complicated because it’s possible to configure which stages in CRM are used for opportunities that have been won. As standard there is a stage called “Won” that is used for this, but you could create more stages with different names if that is appropriate.

So the domain checks for the is_won flag (boolean) on the stage for the opportunity. The field stage_id links the opportunity to the stage.

Invisible filters

As noted above, there are 3 filters defined in the Search View but not shown in the dropdown. These invisible filters are defined here so that they be used elsewhere. Here’s one example:

<filter invisible="1"

string="Late Activities"

name="activities_overdue"

domain="[('activity_ids.date_deadline', '<', context_today().strftime('%Y-%m-%d'))]"

help="Show all opportunities for which the next action date is before today"

/>

  1. This starts with filter, but this time with invisible="1"
  2. String is the description
  3. Name will be used elsewhere
  4. Domain defines what is going to be selected (see below)
  5. Help text is optional
Domain
[('activity_ids.date_deadline', '<', context_today().strftime('%Y-%m-%d'))]"

activity_ids links crm.lead to activities [mail.activity] and the comparison is made with today’s date – in yymmdd format – so if any activity for this Lead is overdue then the filter will select the record.

This filter is used in the Kanban view (from the clock icon) and the “activities” widget

All three of the invisible filters are used in the same way.

See also: Date Filters

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s