Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
5927 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor

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

Autor

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 Odpovědi Zobrazení Aktivita
1
bře 15
4711
3
bře 15
5532
1
čvc 18
4197
0
lis 24
1351
1
čvc 19
4181