Python 如何从另一个模块行计算多个字段

Python 如何从另一个模块行计算多个字段,python,odoo,odoo-13,Python,Odoo,Odoo 13,我有一个模块A,它有一个2个1和这个2个1 partner_user = fields.Many2one('res.partner', string='Hesaby Customer') subscription_manager_id = fields.Many2one('n_hesaby_subscription_manager.subscription_manager', string='Subscription Manager ID') 在模块Bi中,如何知道模块A是

我有一个模块
A
,它有一个2个1和这个2个1

    partner_user = fields.Many2one('res.partner', string='Hesaby Customer')

    subscription_manager_id = fields.Many2one('n_hesaby_subscription_manager.subscription_manager', string='Subscription Manager ID')

在模块
B
i中,如何知道模块A是否已重新记录,且合作伙伴用户等于已创建的用户,然后减少重新记录的
A
id

    created_by = fields.Many2one('res.users', string='Created By', default=lambda self: self.env.uid, readonly=True)

    n_company = fields.Many2one('n_hesaby_subscription_manager.subscription_manager', string='Company')

a我不知道如何开始解决这个问题。你能帮我吗?我已经找了两天的方法了

这是我的电脑

    @api.depends('created_by')
    def _compute_user_compnay(self):
        for n_record in self:
            user_compnay = self.env['res.users'].search([('id', '=', lambda self: self.env.user.id])], limit=1)
            print('user id i think',user_compnay)
            
            user_compnay = self.env['n_hesaby_subscription_manager.subscription_manager'].search([('subscription_manager_lines', 'in', user_compnay)], limit=1)


            n_record.name = result


    created_by = fields.Many2one('res.users', string='Created By', default=lambda self: self.env.uid, readonly=True)


    n_company = fields.Many2one('n_hesaby_subscription_manager.subscription_manager', string='Company',compute='_compute_user_compnay')

编辑 模块A


class n_subscription_manager(models.Model):
    _name = 'n_hesaby_subscription_manager.subscription_manager'
    _description = 'Hesaby subscription manager'
    _inherit = ['mail.thread', 'mail.activity.mixin']

    _columns = {

        'subscription_manager_lines': fields.One2many('n_hesaby_subscription_manager.subscription_manager.lines','subscription_manager_id', string='Subscription Manager Lines'),
        #Other Columns

    }

    subscription_manager_lines = fields.One2many('n_hesaby_subscription_manager.subscription_manager.lines','subscription_manager_id',track_visibility="always", string='Subscription Manager Lines')



class n_subscription_manager_lines(models.Model):
    _name = 'n_hesaby_subscription_manager.subscription_manager.lines'
    _description = 'Hesaby subscription manager lines'
    _columns = {

        'subscription_manager_id': fields.Many2one('n_hesaby_subscription_manager.subscription_manager', string='Subscription Manager ID'),


    }

    print('OUTPUT ok what')
    @api.depends('hesaby_user')
    def _compute_user_of_contact(self):
        print('OUTPUT test')
        for n_use in self:
            result = None
            user = self.env['res.users'].search([('partner_id', '=', n_use.hesaby_user.id)], limit=1)
            print('OUTPUT',user)
            result = user.id
            
        n_use.odoo_user = result
        # n_subscription.subscription_type = n_subscription.partner_id.subscription_type_contact = result


    hesaby_user = fields.Many2one('res.partner', string='Hesaby Customer')
    
    odoo_user = fields.Many2one('res.users', string='Odoo User', compute='_compute_user_of_contact')

    user_rank = fields.Selection(string='User Rank', selection=[
        ('primary_user', 'Primary User'),
        ('user', 'User'),
    ])
    subscription_manager_id = fields.Many2one('n_hesaby_subscription_manager.subscription_manager', string='Subscription Manager ID')


模块B

class n_hesaby_snap(models.Model):
    _name = 'n_hesaby_snap.n_hesaby_snap'
    _inherit = ['mail.thread', 'mail.activity.mixin']
    _description = 'Hesaby Snap'

    @api.depends('created_by')
    def _compute_user_compnay(self):
        for n_record in self:
            
            print('OK!')
            obj = self.env['n_hesaby_subscription_manager.subscription_manager']
            obj.search([('subscription_manager_lines.hesaby_user ', '=', n_record.created_by.partner_id)])

            n_record.n_company = obj

    
    created_by = fields.Many2one('res.users', string='Created By', default=lambda self: self.env.uid, readonly=True)

    n_company = fields.Many2one('n_hesaby_subscription_manager.subscription_manager', string='Company',compute='_compute_user_compnay')

当用户注册为公司创建新联系人并向其中添加用户联系人时,将创建一条
记录

B
如果用户是用户,并且在
A
行中,用户将在网站上访问它


因此,我想当
B
中的一条记录被创建时,
n_company
被计算到记录的
a
中,该记录中有一行用户

当您将
id
与lambda表达式(对函数的引用)进行比较时,搜索方法将返回一个空记录集

使用
self.env.user
而不是使用搜索来获取相同的记录

partner\u user
是一个
res.partner
记录,而
created\u是一个
res.users
记录,您无法对它们进行比较,可能您的意思是,如果由
用户创建的
的相关合作伙伴等于
partner\u user

obj = self.env['sn_hesaby_subscription_manager.subscription_manager']
obj.search([('subscription_manager_lines.partner_user ', '=', n_record.created_by.partner_id.id)])
编辑:

您应该将搜索结果分配给
n_公司
,而不是
obj

您可以找到许多在一行中包含该用户的
A
记录。应该有另一个条件来过滤记录以仅获取一条记录

下面的示例使用默认顺序获取第一条记录

n_record.n_compnay = obj.search([('subscription_manager_lines.hesaby_user ', '=', n_record.created_by.partner_id)], limit=1)

您可以使用
create\u uid
过滤
A
记录,其中
create\u uid
等于
partner\u user
A\u records.filtered(lambda r:r.partner\u user==r.create\u uid)
@Kenly感谢您的回复,请举例说明如何使用it@Kenly我加了更多details@Kenly
\u compute\u user\u of\u contact
在没有正常工作的情况下,我的计算方式有问题吗再次感谢您的帮助我没有收到错误,但没有显示任何内容我编辑了问题,我对拼写感到抱歉我的错误
\u name='n\u hesaby\u subscription\u manager.subscription\u manager'
不是
sn\u hesaby\u subscription\u manager.subscription\u manager
如果我添加了
odoo\u user=fields.manyOne('res.users',string='odoo user'),该怎么办
是我的
n\u hesaby\u subscription\u manager.subscription\u manager.lines
并计算那里的用户,然后搜索
n\u hesaby\u subscription\u manager.subscription\u manager.lines
,搜索
odoo\u用户的
然后搜索
n\u公司所需的
subscription\u manager\u id
,可能我不太了解您的问题,请详细说明您需要做什么,并添加与之相关的代码。请检查我的编辑,您需要使用
obj.search
的结果。