Skip to content

Commit

Permalink
[FIX] account_reconcile_oca: Allow counterpart entries for invoice ma…
Browse files Browse the repository at this point in the history
…tching reconciliation models

Added Tests
  • Loading branch information
ByteMeAsap committed Sep 30, 2024
1 parent 1192154 commit f75805f
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 5 deletions.
51 changes: 46 additions & 5 deletions account_reconcile_oca/models/account_bank_statement_line.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright 2023 Dixmit
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from collections import defaultdict

from dateutil import rrule
Expand Down Expand Up @@ -539,10 +538,30 @@ def _default_reconcile_data(self, from_unreconcile=False):
._apply_rules(self, self._retrieve_partner())
)
if res and res.get("status", "") == "write_off":
model = res["model"]
amount = self.amount_total_signed
if (
model
and model.rule_type == "invoice_matching"
and model.allow_payment_tolerance
and not model.payment_tolerance_param == 0
):
for line in res.get("amls", []):
reconcile_auxiliary_id, line_data = self._get_reconcile_line(
line,
"other",
is_counterpart=True,
)
data+=line_data
else:
for line in res.get("amls", []):
reconcile_auxiliary_id, line_data = self._get_reconcile_line(
line, "other", is_counterpart=True, max_amount=amount
)
amount -= line_data.get("amount")
data+=line_data
return self._recompute_suspense_line(
*self._reconcile_data_by_model(
data, res["model"], reconcile_auxiliary_id
),
*self._reconcile_data_by_model(data, model, reconcile_auxiliary_id),
self.manual_reference,
)
elif res and res.get("amls"):
Expand Down Expand Up @@ -763,9 +782,31 @@ def create(self, mvals):
data += lines
reconcile_auxiliary_id = 1
if res.get("status", "") == "write_off":
model = res["model"]
amount = self.amount
if (
model
and model.rule_type == "invoice_matching"
and model.allow_payment_tolerance
and not model.payment_tolerance_param == 0
):
for line in res.get("amls", []):
reconcile_auxiliary_id, line_data = record._get_reconcile_line(
line,
"other",
is_counterpart=True,
)
data+=line_data
else:
for line in res.get("amls", []):
reconcile_auxiliary_id, line_data = record._get_reconcile_line(
line, "other", is_counterpart=True, max_amount=amount
)
amount -= line_data.get("amount")
data+=line_data
data = record._recompute_suspense_line(
*record._reconcile_data_by_model(
data, res["model"], reconcile_auxiliary_id
data, model, reconcile_auxiliary_id
),
self.manual_reference,
)
Expand Down
56 changes: 56 additions & 0 deletions account_reconcile_oca/tests/test_bank_account_reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,3 +1155,59 @@ def test_invoice_foreign_currency_change(self):
self.assertFalse(f.add_account_move_line_id)
self.assertTrue(f.can_reconcile)
self.assertEqual(3, len(f.reconcile_data_info["data"]))

def test_reconcile_model_payment_tolerance(self):
"""
We want to test what happens when we have a reconcile model with
payment tolerance enabled.
"""
inv_1 = self._create_invoice(
currency_id=self.currency_euro_id,
invoice_amount=100,
date_invoice=time.strftime("%Y-07-15"),
auto_validate=True,
)
self.env["account.reconcile.model"].create(
{
"name": "payment_tolerance_allowed_reconcile_model",
"rule_type": "invoice_matching",
"allow_payment_tolerance": True,
"auto_reconcile": True,
"payment_tolerance_type": "percentage",
"payment_tolerance_param": 2.0,
"line_ids": [
(
0,
0,
{
"account_id": (
self.company.default_cash_difference_expense_account_id.id
)
},
)
],
}
)
bank_stmt = self.acc_bank_stmt_model.create(
{
"company_id": self.env.ref("base.main_company").id,
"journal_id": self.bank_journal_euro.id,
"date": time.strftime("%Y-07-15"),
"name": "test",
}
)
bank_stmt_line = self.acc_bank_stmt_line_model.create(
{
"name": "Demo payment tolerance",
"journal_id": self.bank_journal_euro.id,
"statement_id": bank_stmt.id,
"amount": 98,
"date": time.strftime("%Y-07-15"),
"partner_id": inv_1.partner_id.id,
}
)
self.assertIn(
self.company.default_cash_difference_expense_account_id,
bank_stmt_line.mapped("move_id.line_ids.account_id"),
)
self.assertEqual(3, len(bank_stmt_line.reconcile_data_info["data"]))

0 comments on commit f75805f

Please sign in to comment.