Skip to Content
Menu
This question has been flagged
2 Replies
2406 Views

Hello everyone,

I have a model with a company_id field, I want to create a filter like this:

string="My publications" name="my_pub" domain="[('company_id', 'in', user.own_companies)]"/>

where own_companies is a field I added in res.users:

own_companies = fields.Many2many('res.company')

and I can't do this using security rules because I still have to see the other companies in the website, so I thought the only way is to do it using filters.

The error I got trying this 'incorrect' solution is:

Invalid composed field user.own_companies in domain of  ([('company_id', 'in', user.own_companies)])

in the other hand, there is 'uid' which is the id of the current connected user which helped me filter my own records in another model, how can I create such a variable/field ... which points to the connected user own companies?

Thank you in advance




Avatar
Discard
Author Best Answer

Solution:

def search_ids_search(self, operator, operand):
obj = self.env['publication.publication'].search([('company_id', 'in',self.env.user.company_ids.ids)]).ids
return [('id', 'in', obj)]

and add this in the action: field name="domain">[('search_ids','=',1)]

Avatar
Discard
Best Answer

Try this solution:
[('company_id', 'in', 'company_ids')]

Avatar
Discard
Related Posts Replies Views Activity
1
Jun 25
1604
3
Jul 25
3251
1
May 25
1393
1
May 25
1643
4
May 25
2810