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

[15.0][FIX] account_reconciliation_widget: Avoid unbalanced foreign currency reconciliations + exclude own amls in reconcile models propositions #633

Merged
Show file tree
Hide file tree
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
22 changes: 21 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,26 @@
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
if self.currency_id != self.company_currency_id:
all_amls = to_create + [liquidity_aml_dict]

Check warning on line 202 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#L202

Added line #L202 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 210 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#L210

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

Check warning on line 212 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#L212

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

Check warning on line 216 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#L216

Added line #L216 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
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@
domain += srch_domain
bank_statement_lines = self.env["account.bank.statement.line"].search(domain)

results = self.get_bank_statement_line_data(bank_statement_lines.ids)
results = self.get_bank_statement_line_data(

Check warning on line 331 in account_reconciliation_widget/models/reconciliation_widget.py

View check run for this annotation

Codecov / codecov/patch

account_reconciliation_widget/models/reconciliation_widget.py#L331

Added line #L331 was not covered by tests
bank_statement_lines.ids,
excluded_ids=bank_statement_lines.move_id.line_ids.ids,
)
bank_statement_lines_left = self.env["account.bank.statement.line"].browse(
[line["st_line"]["id"] for line in results["lines"]]
)
Expand Down
Loading