Community mailing list archives

community@mail.odoo.com

Dynamic domain based on other field

by
Andre Kurniawan
- 09/26/2016 02:06:57
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