Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
2433 Vistas

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
Descartar
Autor Mejor respuesta

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
Descartar
Mejor respuesta

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

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
jun 25
1767
3
jul 25
3375
1
may 25
1525
1
may 25
1773
4
may 25
2905