Skip to content

Commit

Permalink
[FIX] l10n_th_multicurrency_revaluation: Corrected journal entry amou…
Browse files Browse the repository at this point in the history
…nts for partial payment revaluations.

This fix where the debit and credit amounts on journal entries were incorrect when performing currency revaluations on partially paid invoices.

Step to test:
1. On 01/01/2024, a vendor bill was issued for 100 CNY at a rate of 1 CNY = 5 THB.
2. A payment of 40 CNY was recorded on the same day at the same rate.
3. A currency revaluation was conducted on 31/01/2024, with the rate adjusted to 1 CNY = 4.30 THB.
4. The journal entry incorrectly reflected an exchange rate difference of 70, calculated as 100 x 5 - 100 x 4.30 (instead of the correct amount, 42 CNY, calculated as (100 - 40) x 5 - (100 - 40) x 4.30).
  • Loading branch information
Your Name authored and saran committed Nov 13, 2024
1 parent c42b372 commit 155991a
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions l10n_th_multicurrency_revaluation/models/account_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@ class AccountAccount(models.Model):
)

_sql_mapping = {
"balance": "COALESCE(SUM(debit),0) - COALESCE(SUM(credit), 0) as balance",
"debit": "COALESCE(SUM(debit), 0) as debit",
"credit": "COALESCE(SUM(credit), 0) as credit",
"foreign_balance": "COALESCE(SUM(amount_currency), 0) as foreign_balance",
"balance": """
CASE WHEN COALESCE(SUM(amount_residual), 0) <> 0
THEN COALESCE(SUM(amount_residual), 0)
ELSE COALESCE(SUM(debit), 0) - COALESCE(SUM(credit), 0) END AS balance""",
"debit": """
CASE WHEN COALESCE(SUM(amount_residual), 0) <> 0 AND
COALESCE(SUM(amount_residual), 0) > 0 THEN COALESCE(SUM(amount_residual), 0)
ELSE COALESCE(SUM(debit), 0) END AS debit""",
"credit": """
CASE WHEN COALESCE(SUM(amount_residual), 0) <> 0 AND
COALESCE(SUM(amount_residual), 0) < 0 THEN -1 * COALESCE(SUM(amount_residual), 0)
ELSE COALESCE(SUM(credit), 0) END AS credit""",
"foreign_balance": """
CASE WHEN COALESCE(SUM(amount_residual_currency), 0) <> 0 THEN
COALESCE(SUM(amount_residual_currency), 0)
ELSE COALESCE(SUM(amount_currency), 0) END AS foreign_balance""",
}

def init(self):
Expand Down Expand Up @@ -107,7 +119,9 @@ def _revaluation_query(self, revaluation_date, start_date=None):
aml.currency_id,
aml.debit,
aml.credit,
aml.amount_currency
aml.amount_currency,
aml.amount_residual,
aml.amount_residual_currency
FROM """
+ tables
+ """
Expand Down

0 comments on commit 155991a

Please sign in to comment.