Browse Source

[FIX] account_financial_report: Fix tests + sql for integration tests

When this module is installed along with other chart account different from generic one,
the number of expected accounts and the computation change (for example, in Spain,
the unaffected earnings account is 129000, choking with group with code prefix 1).

This commit makes the tests resistent to these changes.
pull/663/head
Pedro M. Baeza 7 years ago
committed by Ernesto Tejeda
parent
commit
14a335c604
  1. 12
      account_financial_report/report/trial_balance.py
  2. 7
      account_financial_report/tests/abstract_test.py
  3. 3
      account_financial_report/tests/test_general_ledger.py
  4. 18
      account_financial_report/tests/test_trial_balance.py

12
account_financial_report/report/trial_balance.py

@ -460,13 +460,13 @@ WHERE report_trial_balance_account.account_group_id = aggr.account_group_id
WITH RECURSIVE accgroup AS WITH RECURSIVE accgroup AS
(SELECT (SELECT
accgroup.id, accgroup.id,
coalesce(sum(ra.initial_balance),0) as initial_balance,
coalesce(sum(ra.initial_balance_foreign_currency),0)
sum(coalesce(ra.initial_balance, 0)) as initial_balance,
sum(coalesce(ra.initial_balance_foreign_currency, 0))
as initial_balance_foreign_currency, as initial_balance_foreign_currency,
coalesce(sum(ra.debit),0) as debit,
coalesce(sum(ra.credit),0) as credit,
coalesce(sum(ra.final_balance),0) as final_balance,
coalesce(sum(ra.final_balance_foreign_currency),0)
sum(coalesce(ra.debit, 0)) as debit,
sum(coalesce(ra.credit, 0)) as credit,
sum(coalesce(ra.final_balance, 0)) as final_balance,
sum(coalesce(ra.final_balance_foreign_currency, 0))
as final_balance_foreign_currency as final_balance_foreign_currency
FROM FROM
account_group accgroup account_group accgroup

7
account_financial_report/tests/abstract_test.py

@ -12,7 +12,7 @@ _logger = logging.getLogger(__name__)
class AbstractTest(common.TransactionCase): class AbstractTest(common.TransactionCase):
"""Common technical tests for all reports.""" """Common technical tests for all reports."""
at_install = True
at_install = False
post_install = True post_install = True
accounts = {} accounts = {}
@ -289,9 +289,10 @@ class AbstractTest(common.TransactionCase):
# Same filters with only one account # Same filters with only one account
current_filter = self.base_filters.copy() current_filter = self.base_filters.copy()
current_filter.update(filters) current_filter.update(filters)
report_accounts = report.account_ids.filtered('account_id')
current_filter.update({ current_filter.update({
'filter_account_ids': 'filter_account_ids':
[(6, 0, report.account_ids[0].account_id.ids)],
[(6, 0, report_accounts[0].account_id.ids)],
}) })
report2 = self.model.create(current_filter) report2 = self.model.create(current_filter)
@ -299,7 +300,7 @@ class AbstractTest(common.TransactionCase):
self.assertEqual(len(report2.account_ids), 1) self.assertEqual(len(report2.account_ids), 1)
self.assertEqual(report2.account_ids.name, self.assertEqual(report2.account_ids.name,
report.account_ids[0].name)
report_accounts[0].name)
if self._partner_test_is_possible(filters): if self._partner_test_is_possible(filters):
# Same filters with only one partner # Same filters with only one partner

3
account_financial_report/tests/test_general_ledger.py

@ -89,8 +89,7 @@ class TestGeneralLedgerReport(common.TransactionCase):
unaffected_credit=0 unaffected_credit=0
): ):
move_name = 'expense accrual' move_name = 'expense accrual'
journal = self.env['account.journal'].search([
('code', '=', 'MISC')])
journal = self.env['account.journal'].search([], limit=1)
partner = self.env.ref('base.res_partner_12') partner = self.env.ref('base.res_partner_12')
move_vals = { move_vals = {
'journal_id': journal.id, 'journal_id': journal.id,

18
account_financial_report/tests/test_trial_balance.py

@ -129,8 +129,7 @@ class TestTrialBalanceReport(common.TransactionCase):
unaffected_credit=0 unaffected_credit=0
): ):
move_name = 'expense accrual' move_name = 'expense accrual'
journal = self.env['account.journal'].search([
('code', '=', 'MISC')])
journal = self.env['account.journal'].search([], limit=1)
partner = self.env.ref('base.res_partner_12') partner = self.env.ref('base.res_partner_12')
move_vals = { move_vals = {
'journal_id': journal.id, 'journal_id': journal.id,
@ -213,10 +212,19 @@ class TestTrialBalanceReport(common.TransactionCase):
return lines return lines
def test_00_account_group(self): def test_00_account_group(self):
self.assertEqual(len(self.group1.compute_account_ids.ids), 19)
self.assertEqual(len(self.group2.compute_account_ids.ids), 9)
self.assertGreaterEqual(len(self.group1.compute_account_ids), 19)
self.assertGreaterEqual(len(self.group2.compute_account_ids), 9)
def test_01_account_balance_computed(self): def test_01_account_balance_computed(self):
# Make sure there's no account of type "Current Year Earnings" in the
# groups - We change the code
earning_accs = self.env['account.account'].search([
('user_type_id', '=',
self.env.ref('account.data_unaffected_earnings').id)
])
for acc in earning_accs:
if acc.code.startswith('1') or acc.code.startswith('2'):
acc.code = '999' + acc.code
# Generate the general ledger line # Generate the general ledger line
lines = self._get_report_lines() lines = self._get_report_lines()
self.assertEqual(len(lines['receivable']), 1) self.assertEqual(len(lines['receivable']), 1)
@ -248,7 +256,7 @@ class TestTrialBalanceReport(common.TransactionCase):
self.assertEqual(lines['group1'].credit, 0) self.assertEqual(lines['group1'].credit, 0)
self.assertEqual(lines['group1'].final_balance, 1000) self.assertEqual(lines['group1'].final_balance, 1000)
# Add reversale move of the initial move the first day of fiscal year
# Add reversed move of the initial move the first day of fiscal year
# to check the first day of fiscal year is not used # to check the first day of fiscal year is not used
# to compute the initial balance # to compute the initial balance
self._add_move( self._add_move(

Loading…
Cancel
Save