0

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
KbiR
  • 4,047
  • 6
  • 37
  • 103
iam supreeth
  • 497
  • 4
  • 16

1 Answers1

2

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

Juan Salcedo
  • 1,598
  • 1
  • 16
  • 28
  • thanks, i have tried this.. iam not able to get current ID? i printed and value and tried – iam supreeth Jul 11 '18 at 05:34
  • In the most of cases a `compute` method works in dependency to another field `@api.depends('other_field')`, take a looke the `account_invoice.py` file for the account module to get a better understanding, and please debug your method, or show what your `prints` are showing on – Juan Salcedo Jul 12 '18 at 00:38
  • This works for me to take the current active_id from the URL params... – Ajay Kumar Jan 20 '21 at 07:33