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

I need to add domain to contacts to show only contacts who has the sale team of the active user but the error occurred 

This the error:

EvalError: Can not evaluate python expression: ([('team_id', '=', user.sale_team_id.id)])
Error: Name 'user' is not defined

odoo17
Avatar
Descartar

Hii ,

You cannot directly use 'user' in the action definition. Instead, you need to add a custom field to handle the value. Access to the user record should be managed through ir.rule and not directly in the action.

Thanks,

Mejor respuesta

make domain like this 
[('user_id.sale_team_id', '=', user.sale_team_id.id)]

_inherit = 'res.partner'


    @api.model

    def _get_domain_for_sales_team(self):

        user = self.env.user

        if user.sale_team_id:

            return [('user_id.sale_team_id', '=', user.sale_team_id.id)]

        return []
Add this domain to the action by overriding the corresponding action ID with your custom domain.

Avatar
Descartar
Autor Mejor respuesta

I added the field in res partner :

sale_team_id = fields.Many2one('crm.team', default=lambda self: self.env.user.sale_team_id.id, compute="compute_sale_team_id",store=True)

@api.depends('sale_team_id')
def compute_sale_team_id(self):
for rec in self:
rec.sale_team_id==self.env.user.sale_team_id.id

and i change the domain in xml to:
[('team_id', '=', sale_team_id)]

but the same error appears


Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
jul 25
412
1
jun 25
1039
0
may 25
1158
2
abr 25
3153
1
feb 25
1362