Skip to content

Commit

Permalink
+[IMP] account_reconcile_oca: Improve multicurrency management
Browse files Browse the repository at this point in the history
  • Loading branch information
etobella committed Sep 13, 2024
1 parent 6adc750 commit 1be98ea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
9 changes: 7 additions & 2 deletions account_reconcile_oca/models/account_bank_statement_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ def _recompute_suspense_line(self, data, reconcile_auxiliary_id, manual_referenc
total_amount, precision_digits=self.currency_id.decimal_places
):
can_reconcile = False
currency_amount = self.company_id.currency_id._convert(
total_amount, self.currency_id, self.company_id, self.date
)
if suspense_line:
suspense_line.update(
{
Expand All @@ -246,6 +249,7 @@ def _recompute_suspense_line(self, data, reconcile_auxiliary_id, manual_referenc
}
)
else:

suspense_line = {
"reference": "reconcile_auxiliary;%s" % reconcile_auxiliary_id,
"id": False,
Expand All @@ -260,8 +264,8 @@ def _recompute_suspense_line(self, data, reconcile_auxiliary_id, manual_referenc
"debit": -total_amount if total_amount < 0 else 0.0,
"kind": "suspense",
"currency_id": self.company_id.currency_id.id,
"line_currency_id": self.company_id.currency_id.id,
"currency_amount": -total_amount,
"line_currency_id": self.currency_id.id,
"currency_amount": -currency_amount,
}
reconcile_auxiliary_id += 1
new_data.append(suspense_line)
Expand Down Expand Up @@ -723,6 +727,7 @@ def _reconcile_move_line_vals(self, line, move_id=False):
"partner_id": line.get("partner_id") and line["partner_id"][0],
"credit": line["credit"],
"debit": line["debit"],
"currency_id": line.get("line_currency_id", self.company_id.currency_id.id),
"tax_ids": line.get("tax_ids", []),
"tax_tag_ids": line.get("tax_tag_ids", []),
"group_tax_id": line.get("group_tax_id"),
Expand Down
23 changes: 19 additions & 4 deletions account_reconcile_oca/models/account_reconcile_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,29 @@ def _get_reconcile_line(
currency = line.currency_id or self.company_id.currency_id
original_amount = net_amount = -line.amount_residual
if max_amount:
currency_max_amount = self.company_id.currency_id._convert(
max_amount, currency, self.company_id, date
)
currency_max_amount = max_amount
if currency != self.company_id.currency_id:
# In case of a foreign currency, we need to
# convert the max amount to the foreign currency
#
# We add the rounding to the max amount to avoid
# rounding issues when convertingç
rounding = (
self.company_id.currency_id.rounding
if max_amount > 0
else -self.company_id.currency_id.rounding
)
currency_max_amount = self.company_id.currency_id._convert(
max_amount + rounding, currency, self.company_id, date
)
if (
-currency_amount > currency_max_amount > 0
or -currency_amount < currency_max_amount < 0
):
amount = currency_max_amount
# The rounding should be used only for comparison
amount = self.company_id.currency_id._convert(
max_amount, currency, self.company_id, date
)
net_amount = -max_amount
currency_amount = -amount
amount = currency._convert(
Expand Down

0 comments on commit 1be98ea

Please sign in to comment.