Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Domain for Many2many fields

Alejandro Perez Cosio
on 10/26/15, 11:20 AM 668 views

Hello there, 

I'm trying to create a domain on a Many2many field:

def onchange_domain_on_days(self):
res = {}
ids = []
employee_model = self.env['hr.employee']
all_employees = employee_model.search([])
for employee in all_employees:
if employee.user_id.store_id == self.working_hours_id.store_id:
res['domain'] = {
'monday': [('id', 'in', ids)],
return res

This will work very well! BUT only if the field value 'name' changes.. Is there a way to apply this from the beginning?

Best regards




Akhil P Sivan

--Akhil P Sivan--
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/26/15, 2:30 PM


- One option is to make it a compute field of type Many2many. And you can add the above code on that function, according to what should be returned on that field.

- Another option is to override the view_init() which is triggered everytime showing a form view, you can add your code in that function.

This post also might be helpful, which describes another way:


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 10/26/15, 11:20 AM
Seen: 668 times
Last updated: 10/26/15, 2:30 PM