Skip to content

Commit

Permalink
[IMP] account_statement_base: add smart button on view_bank_statement…
Browse files Browse the repository at this point in the history
…_form linking to journal items
  • Loading branch information
sergiobstoj committed Jun 4, 2024
1 parent e6a8205 commit 59b69f1
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 4 deletions.
1 change: 1 addition & 0 deletions account_statement_base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
1 change: 1 addition & 0 deletions account_statement_base/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_bank_statement_line
22 changes: 22 additions & 0 deletions account_statement_base/models/account_bank_statement_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from odoo import _, models


class AccountBankStatement(models.Model):
_inherit = "account.bank.statement"

def open_entries(self):
self.ensure_one()
return {
"name": _("Journal Items"),
"view_mode": "tree,form",
"res_model": "account.move.line",
"view_id": False,
"type": "ir.actions.act_window",
"context": {"search_default_group_by_move": 1, "expand": 1},
"search_view_id": self.env.ref("account.view_account_move_line_filter").id,
"domain": [
"&",
("parent_state", "=", "posted"),
("statement_id", "=", self.id),
],
}
11 changes: 7 additions & 4 deletions account_statement_base/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -422,7 +423,9 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
1 change: 1 addition & 0 deletions account_statement_base/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_account_statement_base
109 changes: 109 additions & 0 deletions account_statement_base/tests/test_account_statement_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
from odoo.tests import tagged

from odoo.addons.account.tests.common import TestAccountReconciliationCommon


@tagged("post_install", "-at_install")
class TestReconciliationWidget(TestAccountReconciliationCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.acc_bank_stmt_model = cls.env["account.bank.statement"]
cls.account_move_model = cls.env["account.move"]
cls.account_move_line_model = cls.env["account.move.line"]
cls.current_assets_account = cls.env["account.account"].search(
[
("account_type", "=", "asset_current"),
("company_id", "=", cls.company.id),
],
limit=1,
)
cls.current_assets_account.reconcile = True
cls.non_current_assets_account = cls.env["account.account"].search(
[
("account_type", "=", "asset_non_current"),
("company_id", "=", cls.company.id),
],
limit=1,
)
cls.non_current_assets_account.reconcile = True

def test01_open_entries(self):
statement = self.acc_bank_stmt_model.create(
{
"name": "Test Bank Statement",
}
)
domain = [
"&",
("parent_state", "=", "posted"),
("statement_id", "=", statement.id),
]
result = statement.open_entries()
self.assertTrue(result)
self.assertEqual(result.get("res_model"), "account.move.line")
self.assertEqual(result.get("context").get("search_default_group_by_move"), 1)
self.assertEqual(result.get("context").get("expand"), 1)
self.assertEqual(result.get("domain"), domain)

def test02_open_entries(self):
move = self.account_move_model.create(
{
"line_ids": [
(
0,
0,
{
"account_id": self.current_assets_account.id,
"name": "DEMO",
"credit": 100,
},
),
(
0,
0,
{
"account_id": self.non_current_assets_account.id,
"name": "DEMO",
"debit": 100,
},
),
]
}
)
move.action_post()
statement = self.acc_bank_stmt_model.create(
{
"name": "Test Bank Statement",
"line_ids": [
(
0,
0,
{
"date": "2024-01-01",
"amount": 100.0,
"payment_ref": move.name,
"line_ids": [
(4, move.line_ids[0].id),
],
},
),
(
0,
0,
{
"date": "2024-01-01",
"amount": 100.0,
"payment_ref": move.name,
"line_ids": [
(4, move.line_ids[1].id),
],
},
),
],
}
)
result = statement.open_entries()
move_lines = self.env[result["res_model"]].search(result["domain"])
self.assertIn(statement.line_ids.line_ids[0], move_lines)
self.assertIn(statement.line_ids.line_ids[1], move_lines)
10 changes: 10 additions & 0 deletions account_statement_base/views/account_bank_statement.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
context="{'search_default_statement_id': id}"
string="Transactions"
/>
<button
name="open_entries"
type="object"
class="oe_stat_button"
icon="fa-bars"
>
<div class="o_stat_info">
<span class="o_stat_text">Journal Items</span>
</div>
</button>
</div>
<div class="oe_title oe_inline">
<label for="name" />
Expand Down

0 comments on commit 59b69f1

Please sign in to comment.