← Back to team overview

openerp-dev-web team mailing list archive

Usage of 'domain' and 'filter_domain' attributes for <field> elements in search views

 

[This is a copy of the mail sent to the ~openerp-dev mailing-list, sorry
for the spam]

Hello everyone,

This is a notification about a change in the XML API.

Some of you are maybe familiar with the use of <filter> and <field> in
search views, this is about them. A few weeks ago the GTK client was
changed to support a 'domain' attribute for <field> in search view, that
works similarly to the 'domain' attribute of the <filter> elements.

In order to avoid a name clash and much confusion with the regular
'domain' attribute that exists for relational fields (such as many2one),
we have renamed it to 'filter_domain', referring to its behavior similar
to the "domain" of a <filter>.

Example of a normal domain:
---------------------------
<search string="Search view of scrum.product.backlog">
  <field name="project_id" domain="[('scrum', '=', 1)]"/>
</search>

Effect: when using auto-completion for the project_id m2o field, only
projects with the 'scrum' attribute set to "1" would be suggested, and
if using a selection widget, it will only contain scrum projects.
BTW, the domain at the view level (like above) is always combined with
the domain specified in the model directly.

Example of a filter_domain:
---------------------------
<field name="location_id" context="{'location': self}"/>
  <field name="location_id" string="Location"
filter_domain="['|',('location_id','ilike',self),('location_dest_id','ilike',self)]"/>
</search>

Effect: when typing a value in the location_id field of the search view,
the filter_domain is applied instead of the default domain
[('location_id','ilike', self)], so the filtering includes both stock
moves that are going TO and stock moves that are coming FROM the given
locations.

You can of course combine a domain and a filter_domain on the same field
in a search view, but they will have 2 different effects.

fields.dummy and context fields
-------------------------------
Another use of the 'filter_domain' attribute could be to disable the
default behavior of a <field>, by setting filter_domain="[]".
This could be convenient, for example if the field is supposed to be
used to set the context, and not to filter, like the following:

<search string="Product search form with stock installed">
   <field name="location_id" context="{'location': self}"
          filter_domain="[]"/>
</search>

Most of the time you will not need this for context fields because these
fields did not really exist on the object, and have been created as
'fields.dummy' (instead of 'fields.many2one' for example).
A fields.dummy field will not filter the results even if a domain is
applied to it, so we don't really need the filter_domain in this case.

References:
- server/trunk has been updated as of r.2509
- client/trunk has been updated as of r.1398
- addons/trunk has been updated as of r.4108
- web/trunk: to be done, see backlog item 812

PS: This time I will send a copy of this email to all team members of
~openerp-dev, because many developers are not subscribed to the mailing-
list yet. Please make sure everyone subscribes so next time we can
simply use the mailing-list.

Many thanks!
-- 
This message was sent from Launchpad by the user
Olivier Dony (OpenERP) (https://launchpad.net/~odo)
using the "Contact this team" link on the OpenERP R&D Team
team page to each member directly.
For more information see
https://help.launchpad.net/YourAccount/ContactingPeople