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

Add test scripts
  • Loading branch information
ByteMeAsap committed Sep 30, 2024
1 parent 1192154 commit 8278369
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 4 deletions.
50 changes: 46 additions & 4 deletions account_reconcile_oca/models/account_bank_statement_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,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", []):
line_data = self._get_reconcile_line(
line,
"other",
is_counterpart=True,
)
data.append(line_data)
else:
for line in res.get("amls", []):
line_data = self._get_reconcile_line(
line, "other", is_counterpart=True, max_amount=amount
)
amount -= line_data.get("amount")
data.append(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 +783,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", []):
line_data = record._get_reconcile_line(
line,
"other",
is_counterpart=True,
)
data.append(line_data)
else:
for line in res.get("amls", []):
line_data = record._get_reconcile_line(
line, "other", is_counterpart=True, max_amount=amount
)
amount -= line_data.get("amount")
data.append(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
43 changes: 43 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,46 @@ 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 8278369

Please sign in to comment.