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

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
Discard

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,

Best Answer

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
Discard
Author Best Answer

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
Discard
Related Posts Replies Views Activity
2
Oct 24
65
2
Sep 24
331
3
Sep 24
1259
3
Aug 24
269
2
Aug 24
254