[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/868/head
parent
59195c4554
commit
7f238bc7f6
|
@ -460,13 +460,13 @@ WHERE report_trial_balance_account.account_group_id = aggr.account_group_id
|
|||
WITH RECURSIVE accgroup AS
|
||||
(SELECT
|
||||
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,
|
||||
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
|
||||
FROM
|
||||
account_group accgroup
|
||||
|
|
|
@ -12,7 +12,7 @@ _logger = logging.getLogger(__name__)
|
|||
|
||||
class AbstractTest(common.TransactionCase):
|
||||
"""Common technical tests for all reports."""
|
||||
at_install = True
|
||||
at_install = False
|
||||
post_install = True
|
||||
|
||||
accounts = {}
|
||||
|
@ -289,9 +289,10 @@ class AbstractTest(common.TransactionCase):
|
|||
# Same filters with only one account
|
||||
current_filter = self.base_filters.copy()
|
||||
current_filter.update(filters)
|
||||
report_accounts = report.account_ids.filtered('account_id')
|
||||
current_filter.update({
|
||||
'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)
|
||||
|
@ -299,7 +300,7 @@ class AbstractTest(common.TransactionCase):
|
|||
|
||||
self.assertEqual(len(report2.account_ids), 1)
|
||||
self.assertEqual(report2.account_ids.name,
|
||||
report.account_ids[0].name)
|
||||
report_accounts[0].name)
|
||||
|
||||
if self._partner_test_is_possible(filters):
|
||||
# Same filters with only one partner
|
||||
|
|
|
@ -89,8 +89,7 @@ class TestGeneralLedgerReport(common.TransactionCase):
|
|||
unaffected_credit=0
|
||||
):
|
||||
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')
|
||||
move_vals = {
|
||||
'journal_id': journal.id,
|
||||
|
|
|
@ -129,8 +129,7 @@ class TestTrialBalanceReport(common.TransactionCase):
|
|||
unaffected_credit=0
|
||||
):
|
||||
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')
|
||||
move_vals = {
|
||||
'journal_id': journal.id,
|
||||
|
@ -213,10 +212,19 @@ class TestTrialBalanceReport(common.TransactionCase):
|
|||
return lines
|
||||
|
||||
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):
|
||||
# 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
|
||||
lines = self._get_report_lines()
|
||||
self.assertEqual(len(lines['receivable']), 1)
|
||||
|
@ -248,7 +256,7 @@ class TestTrialBalanceReport(common.TransactionCase):
|
|||
self.assertEqual(lines['group1'].credit, 0)
|
||||
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 compute the initial balance
|
||||
self._add_move(
|
||||
|
|
Loading…
Reference in New Issue