Skip to Content
Menu
This question has been flagged
1 Reply
4277 Views

Hello,

I am trying to get the partner total balance. But it is not working properly. If partner have receivable and payable balance both then it is working fine. If receivable or payable balance is zero (0.00) it does not computes the total balance. Following is the code which i am using. can you please check and guide where i am doing wrong.

@api.onchange('debit','credit')
def __total_balance(self): 
 if self.debit and self.credit:
    self.balance = self.debit - self.credit 

Avatar
Discard
Best Answer

it's because if condition ` if self.debit and self.credit:` it only true when a record has debit and credit value otherwise it's false and didn't compute the balance 
so remove the condition it will work fine without it 

Avatar
Discard
Author

thank you for the support. but removing the if condition did not worked for me. Debit and credit fields are default computed fields with no stored value. kindly suggest what should be done as in this case "balance" field is also computed field with no stored value.

regards

then define balance as also compute field instead of on changing it on onchange

balance = fields.Monetary(compute='_compute_balance', string='Total Balance')

@api.mulit

def _compute_balance(self)

for record in self:

record.balance = record.debit - record.credit

Note: if you want it to be searchable implement inverse/search

Author

Thanks a lot it worked. i had two views for debit and credit and one of them was invisible so code update was not working properly. i have changed the code as per your suggestion and removed the duplicate view and it worked.

Cool, it's my pleasure :)

Related Posts Replies Views Activity
1
Mar 15
3449
3
Mar 15
4471
1
Jul 18
2875
0
Nov 24
33
1
Jul 19
2538