Skip to content

Commit

Permalink
[IMP] account_financial_report: general ledger account range
Browse files Browse the repository at this point in the history
  • Loading branch information
WesleyOliveira98 committed Jun 4, 2024
1 parent 5046194 commit bad8897
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
18 changes: 18 additions & 0 deletions account_financial_report/tests/test_general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,3 +742,21 @@ def test_account_type_filter(self):
wizard.account_type_ids = False
wizard._onchange_account_type_ids()
self.assertEqual(wizard.account_ids, account_model)

def test_validate_account_range(self):
accounts = self.env["account.account"].search([])
wizard = self.env["general.ledger.report.wizard"].create(
{
"company_id": False,
"account_code_from": accounts[0].id,
"account_code_to": accounts[9].id,
}
)
wizard.on_change_account_range()
self.assertEqual(wizard.account_ids, accounts[0:10])

company_id = self.env.user.company_id
company_accounts = accounts[0:10].filtered(lambda a: a.company_id == company_id)
wizard.company_id = company_id
wizard.on_change_account_range()
self.assertEqual(wizard.account_ids, company_accounts)
25 changes: 14 additions & 11 deletions account_financial_report/wizard/general_ledger_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,20 @@ def _get_account_move_lines_domain(self):

@api.onchange("account_code_from", "account_code_to")
def on_change_account_range(self):
if (
self.account_code_from
and self.account_code_from.code.isdigit()
and self.account_code_to
and self.account_code_to.code.isdigit()
):
start_range = int(self.account_code_from.code)
end_range = int(self.account_code_to.code)
self.account_ids = self.env["account.account"].search(
[("code", ">=", start_range), ("code", "<=", end_range)]
)
if self.account_code_from and self.account_code_to:
start_range = self.account_code_from.code
end_range = self.account_code_to.code

accounts = self.env["account.account"].search([])
account_codes = [account.code for account in accounts]

start_index = account_codes.index(start_range)
reverse_account_codes = account_codes[::-1]
reverse_end_index = reverse_account_codes.index(end_range)
end_index = len(account_codes) - 1 - reverse_end_index

self.account_ids = accounts[start_index : end_index + 1]

if self.company_id:
self.account_ids = self.account_ids.filtered(
lambda a: a.company_id == self.company_id
Expand Down

0 comments on commit bad8897

Please sign in to comment.