Community mailing list archives

community@mail.odoo.com

Re: Dynamic domain based on other field

by
Same Motion S.A.C, Carlos Rodriguez
- 09/26/2016 13:35:46
Hello I think you can do it in the XML view, example:

<field name="product_ids" domain="['|','&amp;',('id','=',group_id),('use_category','=',False),'&amp;',('category_id','=',group_id),('use_category','=',False)]" options="{&quot;always_reload&quot;: True}"/>

2016-09-26 1:11 GMT-05:00 vak0160 <vak0160.work@gmail.com>:
Hello Community,


I have this model with 4 fields:

- `group_id` (M2O)
- `category_id` (M20)
- `use_category` (Boolean)
- `product_ids` (M2M)


I want to put the domain on `product_ids` field, based on the value of 
`use_category`.

If `use_category` is False, the domain is `[('group_id', '=', group_id)]`.
If `use_category` is True, the domain is `[('category_id', '=', 
category_id)]`.

How can I do that? I already tried with `api.onchange`, but the domain 
is reset each time I re-open that view, and I have to change the 
`use_category` field again to trigger the change.

-- 
Regards,
Andre

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe