Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
1365 Vizualizări

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
Imagine profil
Abandonează

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,

Cel mai bun răspuns

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.

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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


Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
aug. 25
2642
1
iul. 25
1027
1
aug. 25
1151
0
mai 25
1484
2
apr. 25
3642