Skip to content

Commit dbfcfea

Browse files
[IMP] account_invoice_show_currency_rate: use absolute balance to get rate on credit amounts
1 parent f328c90 commit dbfcfea

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

account_invoice_show_currency_rate/models/account_move.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class AccountMove(models.Model):
2020
"state",
2121
"date",
2222
"line_ids.amount_currency",
23+
"line_ids.balance",
2324
"company_id",
2425
"currency_id",
2526
"show_currency_rate_amount",
@@ -32,12 +33,14 @@ def _compute_currency_rate_amount(self):
3233
"""
3334
self.currency_rate_amount = 1
3435
for item in self.filtered("show_currency_rate_amount"):
35-
lines = item.line_ids.filtered(lambda x: x.amount_currency > 0)
36+
lines = item.line_ids.filtered(lambda x: abs(x.amount_currency) > 0)
3637
if item.state == "posted" and lines:
37-
amount_currency_positive = sum(lines.mapped("amount_currency"))
38-
total_debit = sum(lines.mapped("debit"))
38+
amount_currency_positive = sum(
39+
[abs(amc) for amc in lines.mapped("amount_currency")]
40+
)
41+
total_balance_positive = sum([abs(b) for b in lines.mapped("balance")])
3942
item.currency_rate_amount = item.currency_id.round(
40-
amount_currency_positive / total_debit
43+
amount_currency_positive / total_balance_positive
4144
)
4245
else:
4346
rates = item.currency_id._get_rates(item.company_id, item.date)

0 commit comments

Comments
 (0)