Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
5915 Widoki

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 

Awatar
Odrzuć
Najlepsza odpowiedź

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 

Awatar
Odrzuć
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 :)

Powiązane posty Odpowiedzi Widoki Czynność
1
mar 15
4678
3
mar 15
5521
1
lip 18
4182
0
lis 24
1346
1
lip 19
4154