Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] account_reconcile_oca: Fix foreign currency #636

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions account_reconcile_oca/models/account_bank_statement_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,16 @@ def _onchange_add_account_move_line_id(self):
new_data,
self.reconcile_data_info["reconcile_auxiliary_id"],
self.manual_reference,
exchange_recompute=True,
)
self.can_reconcile = self.reconcile_data_info.get("can_reconcile", False)
self.add_account_move_line_id = False

def _recompute_suspense_line(self, data, reconcile_auxiliary_id, manual_reference):
def _recompute_suspense_line(
self, data, reconcile_auxiliary_id, manual_reference, exchange_recompute=False
):
reconcile_auxiliary_id = self._compute_exchange_rate(
data, reconcile_auxiliary_id
data, reconcile_auxiliary_id, exchange_recompute=exchange_recompute
)
can_reconcile = True
total_amount = 0
Expand Down Expand Up @@ -393,7 +396,11 @@ def _reconcile_data_by_model(self, data, reconcile_model, reconcile_auxiliary_id
new_data.append(new_line)
return new_data, reconcile_auxiliary_id

def _compute_exchange_rate(self, data, reconcile_auxiliary_id):
def _compute_exchange_rate(
self, data, reconcile_auxiliary_id, exchange_recompute=False
):
if not exchange_recompute:
return reconcile_auxiliary_id
foreign_currency = (
self.currency_id != self.company_id.currency_id
or self.foreign_currency_id
Expand All @@ -416,6 +423,7 @@ def _compute_exchange_rate(self, data, reconcile_auxiliary_id):
"date": fields.Date.to_string(self.date),
"name": self.payment_ref or self.name,
"amount": -amount,
"net_amount": -amount,
"credit": amount if amount > 0 else 0.0,
"debit": -amount if amount < 0 else 0.0,
"kind": "other",
Expand Down Expand Up @@ -444,7 +452,8 @@ def _default_reconcile_data(self, from_unreconcile=False):
*self._reconcile_data_by_model(
data, res["model"], reconcile_auxiliary_id
),
self.manual_reference
self.manual_reference,
exchange_recompute=True
)
elif res and res.get("amls"):
amount = self.amount_total_signed
Expand All @@ -455,7 +464,10 @@ def _default_reconcile_data(self, from_unreconcile=False):
amount -= line_data.get("amount")
data.append(line_data)
return self._recompute_suspense_line(
data, reconcile_auxiliary_id, self.manual_reference
data,
reconcile_auxiliary_id,
self.manual_reference,
exchange_recompute=True,
)
return self._recompute_suspense_line(
data
Expand Down Expand Up @@ -643,7 +655,8 @@ def create(self, mvals):
*record._reconcile_data_by_model(
data, res["model"], reconcile_auxiliary_id
),
self.manual_reference
self.manual_reference,
exchange_recompute=True
)
elif res.get("amls"):
amount = self.amount
Expand All @@ -654,7 +667,10 @@ def create(self, mvals):
amount -= line_data.get("amount")
data.append(line_data)
data = record._recompute_suspense_line(
data, reconcile_auxiliary_id, self.manual_reference
data,
reconcile_auxiliary_id,
self.manual_reference,
exchange_recompute=True,
)
if not data.get("can_reconcile"):
continue
Expand Down Expand Up @@ -704,7 +720,10 @@ def button_manual_reference_full_paid(self):
else:
new_data.append(line)
self.reconcile_data_info = self._recompute_suspense_line(
new_data, reconcile_auxiliary_id, self.manual_reference
new_data,
reconcile_auxiliary_id,
self.manual_reference,
exchange_recompute=True,
)
self.can_reconcile = self.reconcile_data_info.get("can_reconcile", False)

Expand Down
Loading