Skip to content

Commit

Permalink
[FIX] account_financial_report: Improve test when duplicated group co…
Browse files Browse the repository at this point in the history
…de in CI
  • Loading branch information
carlosdauden committed Jun 22, 2021
1 parent 0ec5bfe commit 26cfef8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
3 changes: 1 addition & 2 deletions account_financial_report/report/trial_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,7 @@ def _get_computed_account_groups(self, account_code, data, groups):
limit_level = len(account_code)
for i in range(limit_level + 1):
group_code = account_code[:i]
# Get last group in case of repeated code (Solves CI test case)
group = groups.filtered(lambda g: g.code_prefix == group_code)[-1:]
group = groups.filtered(lambda g: g.code_prefix == group_code)[:1]
# Only append existing groups if not limit_hierarchy_level
if limit_hierarchy_level or group:
account_groups.append((group_code, group))
Expand Down
29 changes: 24 additions & 5 deletions account_financial_report/tests/test_trial_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def setUp(self):
self.group1 = group_obj.create(
{'code_prefix': '1',
'name': 'Group 1'})
self.group1_bis = group_obj.create(
{'code_prefix': '1',
'name': 'Group 1 bis'})
self.group11 = group_obj.create(
{'code_prefix': '11',
'name': 'Group 11',
Expand Down Expand Up @@ -168,6 +171,17 @@ def _get_group_lines(self, group_id, trial_balance):
}
return lines

def _get_group_lines_by_code(self, group_code, trial_balance):
group = next(filter(
lambda g: g['code'] == group_code and g['type'] == 'group_type',
trial_balance))
return {
'initial_balance': group['initial_balance'],
'debit': group['debit'],
'credit': group['credit'],
'final_balance': group['ending_balance']
}

def check_partner_in_report(self, account_id, partner_id, total_amount):
partner_in_report = False
if account_id in total_amount.keys():
Expand Down Expand Up @@ -243,7 +257,8 @@ def test_01_account_balance_computed(self):
# Check the initial and final balance
account_receivable_lines = self._get_account_lines(
self.account100.id, trial_balance)
group1_lines = self._get_group_lines(self.group1.id, trial_balance)
group1_lines = self._get_group_lines_by_code(
self.group1.code_prefix, trial_balance)

self.assertEqual(account_receivable_lines['initial_balance'], 1000)
self.assertEqual(account_receivable_lines['debit'], 0)
Expand Down Expand Up @@ -281,8 +296,10 @@ def test_01_account_balance_computed(self):
self.account100.id, trial_balance)
account_income_lines = self._get_account_lines(
self.account200.id, trial_balance)
group1_lines = self._get_group_lines(self.group1.id, trial_balance)
group2_lines = self._get_group_lines(self.group2.id, trial_balance)
group1_lines = self._get_group_lines_by_code(
self.group1.code_prefix, trial_balance)
group2_lines = self._get_group_lines_by_code(
self.group2.code_prefix, trial_balance)

self.assertEqual(account_receivable_lines['initial_balance'], 1000)
self.assertEqual(account_receivable_lines['debit'], 0)
Expand Down Expand Up @@ -329,8 +346,10 @@ def test_01_account_balance_computed(self):
self.account100.id, trial_balance)
account_income_lines = self._get_account_lines(
self.account200.id, trial_balance)
group1_lines = self._get_group_lines(self.group1.id, trial_balance)
group2_lines = self._get_group_lines(self.group2.id, trial_balance)
group1_lines = self._get_group_lines_by_code(
self.group1.code_prefix, trial_balance)
group2_lines = self._get_group_lines_by_code(
self.group2.code_prefix, trial_balance)

self.assertEqual(account_receivable_lines['initial_balance'], 1000)
self.assertEqual(account_receivable_lines['debit'], 0)
Expand Down

0 comments on commit 26cfef8

Please sign in to comment.