Skip to content

Commit

Permalink
[IMP] account_financial_report: general ledger filter by account types
Browse files Browse the repository at this point in the history
  • Loading branch information
WesleyOliveira98 authored and henrybackman committed Oct 15, 2024
1 parent d772f9e commit 032fee9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
21 changes: 21 additions & 0 deletions account_financial_report/tests/test_general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,3 +731,24 @@ def test_validate_date_range(self):
wizard.onchange_date_range_id()
self.assertEqual(wizard.date_from, date(2018, 1, 1))
self.assertEqual(wizard.date_to, date(2018, 12, 31))

def test_account_type_filter(self):
company_id = self.env.user.company_id
account_model = self.env["account.account"]
account = account_model.search([], limit=1)
account_type = account.user_type_id
accounts = account_model.search(
[
("company_id", "=", company_id.id),
("user_type_id", "in", account_type.ids),
]
)
wizard = self.env["general.ledger.report.wizard"].create(
{"account_type_ids": account_type, "company_id": company_id.id}
)
wizard.onchange_company_id()
self.assertEqual(wizard.account_ids, accounts)

wizard.account_type_ids = False
wizard._onchange_account_type_ids()
self.assertEqual(wizard.account_ids, account_model)
18 changes: 18 additions & 0 deletions account_financial_report/wizard/general_ledger_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class GeneralLedgerReportWizard(models.TransientModel):
)
receivable_accounts_only = fields.Boolean()
payable_accounts_only = fields.Boolean()
account_type_ids = fields.Many2many(
comodel_name="account.account.type",
string="Account Types",
)
partner_ids = fields.Many2many(
comodel_name="res.partner",
string="Filter partners",
Expand Down Expand Up @@ -111,6 +115,18 @@ def on_change_account_range(self):
lambda a: a.company_id == self.company_id
)

@api.onchange("account_type_ids")
def _onchange_account_type_ids(self):
if self.account_type_ids:
self.account_ids = self.env["account.account"].search(
[
("company_id", "=", self.company_id.id),
("user_type_id", "in", self.account_type_ids.ids),
]
)
else:
self.account_ids = None

def _init_date_from(self):
"""set start date to begin of current year if fiscal year running"""
today = fields.Date.context_today(self)
Expand Down Expand Up @@ -179,6 +195,8 @@ def onchange_company_id(self):
self.account_ids = self.account_ids.filtered(
lambda a: a.company_id == self.company_id
)
if self.company_id and self.account_type_ids:
self._onchange_account_type_ids()
if self.company_id and self.cost_center_ids:
self.cost_center_ids = self.cost_center_ids.filtered(
lambda c: c.company_id == self.company_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
/>
</div>
</div>
<field
name="account_type_ids"
widget="many2many_tags"
options="{'no_create': True}"
/>
<field
name="account_ids"
nolabel="1"
Expand Down

0 comments on commit 032fee9

Please sign in to comment.