Skip to content

Commit

Permalink
[FIX] account_reconciliation_widget: Avoid unbalanced foreign currenc…
Browse files Browse the repository at this point in the history
…y reconciliations

When having a statement line in a foreign currency, each resulting
journal item computes the debit/credit amount from the foreign currency
rate, and then rounding the result to company currency digits.

There's a chance in this process that the journal entry final balance
is not 0 summing the rounded balances in company currency.

For fixing this, there can be several strategies, like creating an
extra journal item for the difference, but I have opted for removing
the difference in the latest counterpart aml, so no extra noise and
no need of account decision algorithm for this extra move.

As currency amounts are correct and are the ones used in reconcilation,
there won't be any problem adjusting this amount.

TT45568
  • Loading branch information
pedrobaeza committed Oct 20, 2023
1 parent 78edfdf commit 8c9e613
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion account_reconciliation_widget/models/account_bank_statement.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from odoo import _, fields, models
from odoo.exceptions import UserError
from odoo.tools import float_is_zero


class AccountBankStatement(models.Model):
Expand Down Expand Up @@ -195,7 +196,25 @@ def _create_counterpart_and_new_aml(
aml_dict["partner_id"] = self.partner_id.id
aml_dict["statement_line_id"] = self.id
self._prepare_move_line_for_currency(aml_dict, date)

# Adjust latest counterpart move debit/credit if currency amount is balanced
# but company amount is not
all_amls = to_create + [liquidity_aml_dict]

Check warning on line 201 in account_reconciliation_widget/models/account_bank_statement.py

View check run for this annotation

Codecov / codecov/patch

account_reconciliation_widget/models/account_bank_statement.py#L201

Added line #L201 was not covered by tests
balance_currency = sum([x["amount_currency"] for x in all_amls])
balance = sum([x["debit"] - x["credit"] for x in all_amls])
if float_is_zero(
balance_currency, precision_rounding=self.currency_id.rounding
) and not float_is_zero(
balance, precision_rounding=self.company_currency_id.rounding
):
aml_dict = to_create[-1]

Check warning on line 209 in account_reconciliation_widget/models/account_bank_statement.py

View check run for this annotation

Codecov / codecov/patch

account_reconciliation_widget/models/account_bank_statement.py#L209

Added line #L209 was not covered by tests
if aml_dict["debit"]:
aml_dict["debit"] = self.company_currency_id.round(

Check warning on line 211 in account_reconciliation_widget/models/account_bank_statement.py

View check run for this annotation

Codecov / codecov/patch

account_reconciliation_widget/models/account_bank_statement.py#L211

Added line #L211 was not covered by tests
aml_dict["debit"] - balance
)
else:
aml_dict["credit"] = self.company_currency_id.round(

Check warning on line 215 in account_reconciliation_widget/models/account_bank_statement.py

View check run for this annotation

Codecov / codecov/patch

account_reconciliation_widget/models/account_bank_statement.py#L215

Added line #L215 was not covered by tests
aml_dict["credit"] + balance
)
# Create write-offs
wo_aml = self.env["account.move.line"]
for aml_dict in new_aml_dicts:
Expand Down

0 comments on commit 8c9e613

Please sign in to comment.