如何获取当前记录ID?

时间:2018-07-11 03:43:07

标签: odoo odoo-10 odoo-11

我有一个计算字段和函数:

当我单击合作伙伴列表视图或看板视图时,应该计算当前记录ID的数据并显示在智能按钮中,这在获取当前ID时遇到了问题。

account_info = fields.Integer(compute='_credit_debit_info', string='# Credits and Debits')

@api.multi
def _credit_debit_info(self):
    print "...Self...",self.ids
    print "...context..",self.env.context.get('active_id')
    print "...context..", self.env.context
    for partner in self:
        if partner.with_context(active_id=True):
            PartnerInfo = self.env['account.move.line'].with_context(active_test=False).search([('partner_id', '=', partner.id),
                    ('account_id', 'in', (partner.property_account_receivable_id.id, partner.property_account_payable_id.id))])
            for acco in PartnerInfo:
                cre = sum(acco.mapped('credit'))
                debit = sum(acco.mapped('debit'))
                partner.account_info = cre - debit

1 个答案:

答案 0 :(得分:1)

您可以使用self.idself._idsself._context.get('active_id')