Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
34578 มุมมอง

i have a compute field and function :

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

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 probelm in getting current ID.


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi Supreeth , 


@api.multi

this method decorator is used to work with a list of id ,
while printing  self.id  you will get a list of ids 


use  @api.one  decorator  to work with a single record ,

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

self.ids you get the current records
[2,5]
then you must walk them through a for
for rid in self:
     var = rid.id
     var2 = rid.name

I hope I've helped

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

try self.id

it is your current record id 

อวตาร
ละทิ้ง
ผู้เขียน

thanks, i have tried this.. iam not able to get current ID? i printed and value and tried

Related Posts ตอบกลับ มุมมอง กิจกรรม
7
ธ.ค. 23
20337
1
พ.ย. 17
5606
2
ส.ค. 25
2846
1
ก.ค. 25
1158
1
ส.ค. 25
1152