2

I've faced several times the situation in which I need to write a Many2many/One2Many field in the left part of a domain and a simple record in the right part. Like the in operator, but the other way around.

What I did is avoid this situation with workarounds, but now, I come up with nothing. My current situation is the following:

If you install project module, you'll see that each project.task object can have a unique responsible (user_id, is a Many2one). If you open tasks view, a filter is automatically loaded to see only your tasks:

<filter string="My Tasks" name="my_tasks" domain="[('user_id','=',uid)]"/>

But, what I need is to allow the assignment of several users to the same task. So first, I've create a Many2many field in project.task:

user_ids = fields.Many2many(
    comodel_name='res.users',
    string='Project Managers',
    default=lambda self: self.env.user.mapped('id')
)

Everything works fine, however, now I need to make the filter work the same way as earlier, but with this field. Here is where I'm stucked and need an hypothetical operator contains.

<filter string="My Tasks" name="my_tasks" domain="[('user_ids','contains',uid)]"/>

Did anyone deal with this situation? Any ideas?

forvas
  • 9,801
  • 7
  • 62
  • 158

1 Answers1

0

Ok, I've realized that the operator '=' works as though it was a 'contains' as well. So it's really easy to implement this issue, since the new filter must be exactly like it was but changing the field name:

<filter string="My Tasks" name="my_tasks" domain="[('user_ids','=',uid)]"/>

I've tried this on version 10 and it's working!

These questions give me the hint:

Odoo 8: Many2many domain filter

How to check if field 'contains' the value in Odoo

forvas
  • 9,801
  • 7
  • 62
  • 158