如何为帐户移动设置记录规则以显示用户自己的记录及其销售团队成员记录 Odoo 15?

How to set record rule for account move to show user own records and their saleteams member records Odoo 15?

是否可以通过记录规则来做到这一点?

示例:

用户 A 与成员 B、C、D 有销售团队。 A是这支队伍的队长。

所以如果我们登录A,然后转到account.move,我们可以看到A、B、C、D的记录。

如果我们登录到b,我们只能看到B记录。

谢谢。

注意:其他方案也可以,不需要记录规则。

感谢 Jainesh Shah(Aktiv 软件)

我找到了答案,那就是使用 search_read() 函数:

# -*- coding: utf-8 -*-

from odoo import fields, models, api, _


class AccountMove(models.Model):
    _inherit = 'account.move'

    def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None):
        # find list members of sale team which leaded by current user (current user is leader of this sale team)
        sale_teams = self.env['crm.team'].search([('user_id', '=', self.env.user.id)]).mapped('member_ids')

        # if current user is in group crm_account_move_restrict_records and also the leader of a team
        # then we will show all data of this user and members of the team that this user is leading
        if self.env.user.has_group('z_crm_contract_for_baan.crm_account_move_restrict_records'):
            if sale_teams:
                # add domain
                # get data by team members
                domain += ['|', ('user_id', 'in', sale_teams.ids)]
            # add domain
            # get data by current user
            domain += [('user_id', '=', self.env.user.id)]
        return super(AccountMove, self).search_read(domain=domain, fields=fields, offset=offset, limit=limit, order=order)

感谢大家的帮助,尤其是 Jainesh Shah(Aktiv Software)。