Skip to content

Commit 6b350bf

Browse files
committed
[FIX] account_financial_report: Ability to filter by code
The way accounts are collected has been modified, as they were returning ‘NewId’, which meant that filtering was not possible at any point. I check whether the first position is already a ‘NewId’ and, if so, I browse the IDs so that ‘self.account_ids’ is filled in correctly and filtered correctly.
1 parent 7102d72 commit 6b350bf

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

account_financial_report/tests/test_trial_balance.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,3 +715,36 @@ def test_05_all_accounts_loaded(self):
715715
]
716716
self.assertEqual(len(trial_balance_code_set), len(all_accounts_code_set))
717717
self.assertTrue(trial_balance_code_set == all_accounts_code_set)
718+
719+
def test_06_all_accounts_loaded_newid(self):
720+
all_accounts = (
721+
self.env["account.account"]
722+
.search([], order="code")
723+
.filtered(lambda acc: re.fullmatch(r"[0-9]+(\.[0-9]+)?", acc.code))
724+
)
725+
company = self.env.user.company_id
726+
trial_balance = self.env["trial.balance.report.wizard"].new(
727+
{
728+
"date_from": self.date_start,
729+
"date_to": self.date_end,
730+
"target_move": "posted",
731+
"hide_account_at_0": False,
732+
"show_hierarchy": False,
733+
"company_id": company.id,
734+
"fy_start_date": self.fy_date_start,
735+
"account_code_from": self.account001.id,
736+
"account_code_to": all_accounts[-1].id,
737+
}
738+
)
739+
trial_balance.on_change_account_range()
740+
# sets are needed because some codes are duplicated and
741+
# thus the length of all_accounts would be higher
742+
all_accounts_code_set = set()
743+
trial_balance_code_set = set()
744+
[all_accounts_code_set.add(account.code) for account in all_accounts]
745+
[
746+
trial_balance_code_set.add(account.code)
747+
for account in trial_balance.account_ids
748+
]
749+
self.assertEqual(len(trial_balance_code_set), len(all_accounts_code_set))
750+
self.assertTrue(trial_balance_code_set == all_accounts_code_set)

account_financial_report/wizard/trial_balance_wizard.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,18 @@ def on_change_account_range(self):
9191
self.account_ids = self.env["account.account"].search(
9292
[("code", ">=", start_range), ("code", "<=", end_range)]
9393
)
94-
if self.company_id:
95-
self.account_ids = self.account_ids.filtered(
96-
lambda a: self.company_id in a.company_ids
97-
)
94+
if isinstance(self.account_ids[0].id, models.NewId):
95+
real_ids = self.account_ids.ids
96+
account_ids = self.env["account.account"].browse(real_ids)
97+
if self.company_id:
98+
self.account_ids = account_ids.filtered(
99+
lambda a: self.company_id in a.company_ids
100+
)
101+
else:
102+
if self.company_id:
103+
self.account_ids = self.account_ids.filtered(
104+
lambda a: self.company_id in a.company_ids
105+
)
98106

99107
@api.constrains("show_hierarchy", "show_hierarchy_level")
100108
def _check_show_hierarchy_level(self):

0 commit comments

Comments
 (0)