-
-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] account_reconcile_oca: Reconcile multiple lines
- Loading branch information
Showing
12 changed files
with
221 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import models | ||
from . import wizards | ||
from .hooks import post_init_hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
- Enric Tobella | ||
- Simone Rubino |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_account_account_reconcile,account.account.reconcile,model_account_account_reconcile,account.group_account_user,1,1,0,0 | ||
access_account_account_reconcile_data,account.account.reconcile,model_account_account_reconcile_data,account.group_account_user,1,1,1,1 | ||
account_reconcile_oca.access_account_reconcile_oca_reconcile_multiple_lines,Allow account user to reconcile multiple lines with a reconciliation model,account_reconcile_oca.model_account_reconcile_oca_reconcile_multiple_lines,account.group_account_user,1,1,1,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import test_bank_account_reconcile | ||
from . import test_account_reconcile | ||
from . import test_reconcile_multiple_lines |
88 changes: 88 additions & 0 deletions
88
account_reconcile_oca/tests/test_reconcile_multiple_lines.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Copyright 2025 Simone Rubino | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import Command | ||
from odoo.tests import Form, tagged | ||
|
||
from odoo.addons.account_reconcile_model_oca.tests.common import ( | ||
TestAccountReconciliationCommon, | ||
) | ||
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestReconcileMultipleLines(TestAccountReconciliationCommon): | ||
@classmethod | ||
def setUpClass(cls, chart_template_ref=None): | ||
super().setUpClass(chart_template_ref=chart_template_ref) | ||
(cls.reconcile_account,) = cls.env["account.account"].create( | ||
[ | ||
{ | ||
"name": "Test account for reconciliation", | ||
"code": "TSTREC", | ||
"account_type": "liability_payable", | ||
} | ||
] | ||
) | ||
|
||
cls.bank_journal = cls.company_data["default_journal_bank"] | ||
( | ||
cls.bank_line_1, | ||
cls.bank_line_2, | ||
) = cls.env["account.bank.statement.line"].create( | ||
[ | ||
{ | ||
"journal_id": cls.bank_journal.id, | ||
"date": "2020-01-01", | ||
"amount": 100, | ||
}, | ||
{ | ||
"journal_id": cls.bank_journal.id, | ||
"date": "2020-01-01", | ||
"amount": 600, | ||
}, | ||
], | ||
) | ||
(cls.reconcile_model,) = cls.env["account.reconcile.model"].create( | ||
[ | ||
{ | ||
"name": "Test Writeoff", | ||
"rule_type": "writeoff_button", | ||
"line_ids": [ | ||
Command.create( | ||
{ | ||
"account_id": cls.reconcile_account.id, | ||
} | ||
), | ||
], | ||
}, | ||
] | ||
) | ||
|
||
def _get_wizard(self, statement_lines, reconcile_model): | ||
selection_context = { | ||
"active_model": statement_lines._name, | ||
"active_ids": statement_lines.ids, | ||
} | ||
wizard_model = self.env[ | ||
"account_reconcile_oca.reconcile_multiple_lines" | ||
].with_context(**selection_context) | ||
wizard_form = Form(wizard_model) | ||
wizard_form.manual_model_id = reconcile_model | ||
return wizard_form.save() | ||
|
||
def test_writeoff_2_lines(self): | ||
"""The wizard can writeoff 2 statement lines.""" | ||
# Arrange | ||
reconcile_account = self.reconcile_account | ||
statement_lines = self.bank_line_1 | self.bank_line_2 | ||
writeoff_reconcile_model = self.reconcile_model | ||
wizard = self._get_wizard(statement_lines, writeoff_reconcile_model) | ||
# pre-condition | ||
self.assertEqual(writeoff_reconcile_model.rule_type, "writeoff_button") | ||
self.assertNotIn(reconcile_account, statement_lines.line_ids.account_id) | ||
|
||
# Act | ||
wizard.run() | ||
|
||
# Assert | ||
self.assertIn(reconcile_account, statement_lines.line_ids.account_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import reconcile_multiple_lines |
38 changes: 38 additions & 0 deletions
38
account_reconcile_oca/wizards/reconcile_multiple_lines views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- | ||
~ Copyright 2025 Simone Rubino | ||
~ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
--> | ||
<odoo> | ||
|
||
<record id="reconcile_multiple_lines_view_form" model="ir.ui.view"> | ||
<field | ||
name="name" | ||
>Form view to reconcile multiple lines with a reconciliation model</field> | ||
<field name="model">account_reconcile_oca.reconcile_multiple_lines</field> | ||
<field name="arch" type="xml"> | ||
<form> | ||
<sheet> | ||
<group> | ||
<field name="manual_model_id" /> | ||
</group> | ||
</sheet> | ||
<footer> | ||
<button string="Run" class="btn-primary" type="object" name="run" /> | ||
<button string="Cancel" special="cancel" /> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="reconcile_multiple_lines_action" model="ir.actions.act_window"> | ||
<field name="name">Reconcile with model</field> | ||
<field name="res_model">account_reconcile_oca.reconcile_multiple_lines</field> | ||
<field name="view_mode">form</field> | ||
<field name="target">new</field> | ||
<field | ||
name="binding_model_id" | ||
ref="account.model_account_bank_statement_line" | ||
/> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright 2025 Simone Rubino | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, fields, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class ReconcileMultipleLines(models.TransientModel): | ||
_name = "account_reconcile_oca.reconcile_multiple_lines" | ||
_description = "Reconcile multiple lines with a reconciliation model" | ||
|
||
manual_model_id = fields.Many2one( | ||
comodel_name="account.reconcile.model", | ||
required=True, | ||
) | ||
|
||
def _get_statement_lines(self): | ||
model = self.env.context.get("active_model") | ||
ids = self.env.context.get("active_ids") | ||
statement_lines = self.env[model].browse(ids) | ||
return statement_lines | ||
|
||
def _apply_model_to_line(self, reconciliation_model, statement_line): | ||
reconciliation_model.ensure_one() | ||
statement_line.ensure_one() | ||
partner = reconciliation_model._get_partner_from_mapping(statement_line) | ||
if not reconciliation_model._is_applicable_for(statement_line, partner): | ||
raise UserError( | ||
_( | ||
"Reconcilation model %(model)s " | ||
"cannot be applied to line %(line)s.\n" | ||
"Please select a compatible reconciliation model " | ||
"or deselect the line.", | ||
model=reconciliation_model.display_name, | ||
line=statement_line.display_name, | ||
) | ||
) | ||
statement_line.manual_model_id = reconciliation_model | ||
statement_line._onchange_manual_model_id() | ||
statement_line.reconcile_bank_line() | ||
|
||
def run(self): | ||
statement_lines = self._get_statement_lines() | ||
reconciliation_model = self.manual_model_id | ||
for line in statement_lines: | ||
self._apply_model_to_line(reconciliation_model, line) |