iam supreeth
iam supreeth

Reputation: 497

How to get current record ID?

I have a compute field and function :

When I click on res.partner list view or kanban view, the current record id's data should get calculated and display in smart button, am facing problem in getting the current 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

Upvotes: 0

Views: 6267

Answers (1)

Juan Salcedo
Juan Salcedo

Reputation: 1668

You could use self.id or self._ids or self._context.get('active_id').

Upvotes: 3

Related Questions