diff --git a/account_financial_report/tests/test_general_ledger.py b/account_financial_report/tests/test_general_ledger.py
index 2e9187bc46a8..5bd2f7b77e0b 100644
--- a/account_financial_report/tests/test_general_ledger.py
+++ b/account_financial_report/tests/test_general_ledger.py
@@ -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)
diff --git a/account_financial_report/wizard/general_ledger_wizard.py b/account_financial_report/wizard/general_ledger_wizard.py
index 411de9162c43..133df257ff96 100644
--- a/account_financial_report/wizard/general_ledger_wizard.py
+++ b/account_financial_report/wizard/general_ledger_wizard.py
@@ -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",
@@ -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)
@@ -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
diff --git a/account_financial_report/wizard/general_ledger_wizard_view.xml b/account_financial_report/wizard/general_ledger_wizard_view.xml
index 8e3616d68152..995a28eb2511 100644
--- a/account_financial_report/wizard/general_ledger_wizard_view.xml
+++ b/account_financial_report/wizard/general_ledger_wizard_view.xml
@@ -52,6 +52,11 @@
/>
+