Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
1368 Представления

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
Аватар
Отменить

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,

Лучший ответ

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.

Аватар
Отменить
Автор Лучший ответ

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


Аватар
Отменить
Related Posts Ответы Просмотры Активность
2
авг. 25
2647
1
июл. 25
1032
1
авг. 25
1151
0
мая 25
1490
2
апр. 25
3645