Help

1

What is diff between domain, domain filter and attr ?

Avatar
Dharmraj

Can any one explain me the use of domain , domain filter and attrs in xml files ? Please also explain that which should be used in which scenario.

Avatar
Discard
1Answer
5
Best Answer

Domain = It's a filter you can apply on a relation field. For example, if you hae a relation to res.partner, with domain you can obtain only customer in the search.

Example: Search only customer in a many2one field with res.partner relaton

<field name="partner_id" string="Partner" domain="[('customer','=',True)]"/>

Filter Domain = It's a composite filter you can use in the search field. For example, when you searcha product in the warehouse section, you can search it by name or by code because the module use domain_filter to create a composite filter

Example: Search product for name or code in te some search field

<field name="name" string="Product" filter_domain="['|',('name','ilike',self),('default_code','ilike',self)]"/>

Attrs = They are a series of values use to indicates some parameters for the field in relation with other parameter. For example you can change the reaonly, invisible or required state of a field in relation to another field in thesome form.

Example: Field name readonly if state is not draft and required if amount is 0

<field name="name" attrs={'readonly':[('state', '!=', 'draft'), 'required':[('amount', '=', 0)]}/>
2Comments
Avatar
Discard
Avatar
Dharmraj
-

Explained very well :) Thank you Francesco :)

Avatar
Francesco OpenCode
-

Nice help you...;)