Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] account_financial_report: general ledger account range #1165

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading