Skip to content

Commit

Permalink
[IMP] account_invoice_show_currency_rate: use absolute balance to get…
Browse files Browse the repository at this point in the history
… rate on credit amounts
  • Loading branch information
JordiMForgeFlow committed Nov 11, 2024
1 parent 741052f commit b7197f6
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions account_invoice_show_currency_rate/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AccountMove(models.Model):
"state",
"date",
"line_ids.amount_currency",
"line_ids.balance",
"company_id",
"currency_id",
"show_currency_rate_amount",
Expand All @@ -30,12 +31,14 @@ def _compute_currency_rate_amount(self):
"""
self.currency_rate_amount = 1
for item in self.filtered("show_currency_rate_amount"):
lines = item.line_ids.filtered(lambda x: x.amount_currency > 0)
lines = item.line_ids.filtered(lambda x: abs(x.amount_currency) > 0)
if item.state == "posted" and lines:
amount_currency_positive = sum(lines.mapped("amount_currency"))
total_debit = sum(lines.mapped("debit"))
amount_currency_positive = sum(
[abs(amc) for amc in lines.mapped("amount_currency")]
)
total_balance_positive = sum([abs(b) for b in lines.mapped("balance")])
item.currency_rate_amount = item.currency_id.round(
amount_currency_positive / total_debit
amount_currency_positive / total_balance_positive
)
else:
rates = item.currency_id._get_rates(item.company_id, item.date)
Expand All @@ -60,7 +63,7 @@ class AccountMoveLine(models.Model):
"move_id.state",
"move_id.date",
"amount_currency",
"debit",
"balance",
"move_id.company_id",
"currency_id",
)
Expand All @@ -77,9 +80,10 @@ def _compute_currency_rate_amount(self):
or item.currency_id == item.move_id.company_id.currency_id
):
continue
if item.move_id.state == "posted" and item.amount_currency > 0:
amount_currency = abs(item.amount_currency)
if item.move_id.state == "posted" and amount_currency > 0:
item.currency_rate_amount = item.currency_id.round(
item.amount_currency / item.debit
amount_currency / abs(item.balance)
)
else:
rates = item.currency_id._get_rates(
Expand Down

0 comments on commit b7197f6

Please sign in to comment.