Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
1374 Visualizzazioni

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
Abbandona

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,

Risposta migliore

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
Abbandona
Autore Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
ago 25
2653
1
lug 25
1034
1
ago 25
1151
0
mag 25
1491
2
apr 25
3645