Refactoring and add new tests
parent
79e0669787
commit
4a01fb5bba
|
@ -2,6 +2,7 @@
|
||||||
# © 2016 Julien Coux (Camptocamp)
|
# © 2016 Julien Coux (Camptocamp)
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).-
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).-
|
||||||
|
|
||||||
|
from . import abstract_test
|
||||||
from . import test_aged_partner_balance
|
from . import test_aged_partner_balance
|
||||||
from . import test_general_ledger
|
from . import test_general_ledger
|
||||||
from . import test_open_items
|
from . import test_open_items
|
||||||
|
|
|
@ -0,0 +1,202 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Author: Julien Coux
|
||||||
|
# Copyright 2016 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from openerp.tests.common import TransactionCase
|
||||||
|
|
||||||
|
|
||||||
|
class AbstractTest(TransactionCase):
|
||||||
|
"""Common technical tests for all reports."""
|
||||||
|
|
||||||
|
def setUp(cls):
|
||||||
|
super(AbstractTest, cls).setUp()
|
||||||
|
|
||||||
|
cls.model = cls._getReportModel()
|
||||||
|
|
||||||
|
cls.qweb_report_name = cls._getQwebReportName()
|
||||||
|
cls.xlsx_report_name = cls._getXlsxReportName()
|
||||||
|
cls.xlsx_action_name = cls._getXlsxReportActionName()
|
||||||
|
|
||||||
|
cls.report_title = cls._getReportTitle()
|
||||||
|
|
||||||
|
cls.base_filters = cls._getBaseFilters()
|
||||||
|
cls.additional_filters = cls._getAdditionalFiltersToBeTested()
|
||||||
|
|
||||||
|
cls.report = cls.model.create(cls.base_filters)
|
||||||
|
|
||||||
|
def test_01_generation_report_qweb(self):
|
||||||
|
"""Check if report PDF/HTML is correctly generated"""
|
||||||
|
|
||||||
|
# Check if returned report action is correct
|
||||||
|
report_action = self.report.print_report()
|
||||||
|
self.assertDictContainsSubset(
|
||||||
|
{
|
||||||
|
'type': 'ir.actions.report.xml',
|
||||||
|
'report_name': self.qweb_report_name,
|
||||||
|
'report_type': 'qweb-pdf',
|
||||||
|
},
|
||||||
|
report_action
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check if report template is correct
|
||||||
|
report_html = self.env['report'].get_html(
|
||||||
|
self.report, self.qweb_report_name
|
||||||
|
)
|
||||||
|
self.assertRegexpMatches(report_html, self.report_title)
|
||||||
|
self.assertRegexpMatches(report_html, self.report.account_ids[0].name)
|
||||||
|
|
||||||
|
def test_02_generation_report_xlsx(self):
|
||||||
|
"""Check if report XLSX is correctly generated"""
|
||||||
|
|
||||||
|
# Check if returned report action is correct
|
||||||
|
report_action = self.report.print_report(xlsx_report=True)
|
||||||
|
self.assertDictContainsSubset(
|
||||||
|
{
|
||||||
|
'type': 'ir.actions.report.xml',
|
||||||
|
'report_name': self.xlsx_report_name,
|
||||||
|
'report_type': 'xlsx',
|
||||||
|
},
|
||||||
|
report_action
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check if report template is correct
|
||||||
|
report_xlsx = self.env.ref(self.xlsx_action_name).render_report(
|
||||||
|
self.report.ids,
|
||||||
|
self.xlsx_report_name,
|
||||||
|
{'report_type': 'xlsx'}
|
||||||
|
)
|
||||||
|
self.assertGreaterEqual(len(report_xlsx[0]), 1)
|
||||||
|
self.assertEqual(report_xlsx[1], 'xlsx')
|
||||||
|
|
||||||
|
def test_03_compute_data(self):
|
||||||
|
"""Check that the SQL queries work with all filters options"""
|
||||||
|
|
||||||
|
for filters in [{}] + self.additional_filters:
|
||||||
|
current_filter = self.base_filters.copy()
|
||||||
|
current_filter.update(filters)
|
||||||
|
|
||||||
|
report = self.model.create(current_filter)
|
||||||
|
report.compute_data_for_report()
|
||||||
|
|
||||||
|
self.assertGreaterEqual(len(report.account_ids), 1)
|
||||||
|
|
||||||
|
# Same filters with only one account
|
||||||
|
current_filter = self.base_filters.copy()
|
||||||
|
current_filter.update(filters)
|
||||||
|
current_filter.update({
|
||||||
|
'filter_account_ids':
|
||||||
|
[(6, 0, report.account_ids[0].account_id.ids)],
|
||||||
|
})
|
||||||
|
|
||||||
|
report2 = self.model.create(current_filter)
|
||||||
|
report2.compute_data_for_report()
|
||||||
|
|
||||||
|
self.assertEqual(len(report2.account_ids), 1)
|
||||||
|
self.assertEqual(report2.account_ids.name,
|
||||||
|
report.account_ids[0].name)
|
||||||
|
|
||||||
|
if self._partner_test_is_possible(filters):
|
||||||
|
# Same filters with only one partner
|
||||||
|
report_partner_ids = report.account_ids.mapped('partner_ids')
|
||||||
|
partner_ids = report_partner_ids.mapped('partner_id')
|
||||||
|
|
||||||
|
current_filter = self.base_filters.copy()
|
||||||
|
current_filter.update(filters)
|
||||||
|
current_filter.update({
|
||||||
|
'filter_partner_ids': [(6, 0, partner_ids[0].ids)],
|
||||||
|
})
|
||||||
|
|
||||||
|
report3 = self.model.create(current_filter)
|
||||||
|
report3.compute_data_for_report()
|
||||||
|
|
||||||
|
self.assertGreaterEqual(len(report3.account_ids), 1)
|
||||||
|
|
||||||
|
report_partner_ids3 = report3.account_ids.mapped('partner_ids')
|
||||||
|
partner_ids3 = report_partner_ids3.mapped('partner_id')
|
||||||
|
|
||||||
|
self.assertEqual(len(partner_ids3), 1)
|
||||||
|
self.assertEqual(
|
||||||
|
partner_ids3.name,
|
||||||
|
partner_ids[0].name
|
||||||
|
)
|
||||||
|
|
||||||
|
# Same filters with only one partner and one account
|
||||||
|
report_partner_ids = report3.account_ids.mapped('partner_ids')
|
||||||
|
report_account_id = report_partner_ids.filtered(
|
||||||
|
lambda p: p.partner_id
|
||||||
|
)[0].report_account_id
|
||||||
|
|
||||||
|
current_filter = self.base_filters.copy()
|
||||||
|
current_filter.update(filters)
|
||||||
|
current_filter.update({
|
||||||
|
'filter_account_ids':
|
||||||
|
[(6, 0, report_account_id.account_id.ids)],
|
||||||
|
'filter_partner_ids': [(6, 0, partner_ids[0].ids)],
|
||||||
|
})
|
||||||
|
|
||||||
|
report4 = self.model.create(current_filter)
|
||||||
|
report4.compute_data_for_report()
|
||||||
|
|
||||||
|
self.assertEqual(len(report4.account_ids), 1)
|
||||||
|
self.assertEqual(report4.account_ids.name,
|
||||||
|
report_account_id.account_id.name)
|
||||||
|
|
||||||
|
report_partner_ids4 = report4.account_ids.mapped('partner_ids')
|
||||||
|
partner_ids4 = report_partner_ids4.mapped('partner_id')
|
||||||
|
|
||||||
|
self.assertEqual(len(partner_ids4), 1)
|
||||||
|
self.assertEqual(
|
||||||
|
partner_ids4.name,
|
||||||
|
partner_ids[0].name
|
||||||
|
)
|
||||||
|
|
||||||
|
def _partner_test_is_possible(self, filters):
|
||||||
|
"""
|
||||||
|
:return:
|
||||||
|
a boolean to indicate if partner test is possible
|
||||||
|
with current filters
|
||||||
|
"""
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _getReportModel(self):
|
||||||
|
"""
|
||||||
|
:return: the report model name
|
||||||
|
"""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def _getQwebReportName(self):
|
||||||
|
"""
|
||||||
|
:return: the qweb report name
|
||||||
|
"""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def _getXlsxReportName(self):
|
||||||
|
"""
|
||||||
|
:return: the xlsx report name
|
||||||
|
"""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def _getXlsxReportActionName(self):
|
||||||
|
"""
|
||||||
|
:return: the xlsx report action name
|
||||||
|
"""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def _getReportTitle(self):
|
||||||
|
"""
|
||||||
|
:return: the report title displayed into the report
|
||||||
|
"""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def _getBaseFilters(self):
|
||||||
|
"""
|
||||||
|
:return: the minimum required filters to generate report
|
||||||
|
"""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def _getAdditionalFiltersToBeTested(self):
|
||||||
|
"""
|
||||||
|
:return: the additional filters to generate report variants
|
||||||
|
"""
|
||||||
|
raise NotImplementedError()
|
|
@ -4,71 +4,39 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from openerp.tests.common import TransactionCase
|
from . import abstract_test
|
||||||
|
|
||||||
|
|
||||||
class TestAgedPartnerBalance(TransactionCase):
|
class TestAgedPartnerBalance(abstract_test.AbstractTest):
|
||||||
|
"""
|
||||||
|
Technical tests for Aged Partner Balance Report.
|
||||||
|
"""
|
||||||
|
|
||||||
def setUp(cls):
|
def _getReportModel(self):
|
||||||
super(TestAgedPartnerBalance, cls).setUp()
|
return self.env['report_aged_partner_balance_qweb']
|
||||||
env = cls.env
|
|
||||||
model = env['report_aged_partner_balance_qweb']
|
|
||||||
main_company = env.ref('base.main_company')
|
|
||||||
|
|
||||||
cls.report = model.create({
|
def _getQwebReportName(self):
|
||||||
'date_at': time.strftime('%Y-12-31'),
|
return 'account_financial_report_qweb.report_aged_partner_balance_qweb'
|
||||||
'company_id': main_company.id,
|
|
||||||
})
|
|
||||||
|
|
||||||
def test_01_compute_data(self):
|
def _getXlsxReportName(self):
|
||||||
"""Check if data are computed"""
|
return 'account_financial_report_qweb.report_aged_partner_balance_xlsx'
|
||||||
self.report.compute_data_for_report()
|
|
||||||
self.assertGreaterEqual(len(self.report.account_ids), 1)
|
|
||||||
|
|
||||||
def test_02_generation_report_qweb(self):
|
def _getXlsxReportActionName(self):
|
||||||
"""Check if report PDF/HTML is correctly generated"""
|
return 'account_financial_report_qweb.' \
|
||||||
|
|
||||||
report_name = 'account_financial_report_qweb.' \
|
|
||||||
'report_aged_partner_balance_qweb'
|
|
||||||
# Check if returned report action is correct
|
|
||||||
report_action = self.report.print_report()
|
|
||||||
self.assertDictContainsSubset(
|
|
||||||
{
|
|
||||||
'type': 'ir.actions.report.xml',
|
|
||||||
'report_name': report_name,
|
|
||||||
'report_type': 'qweb-pdf',
|
|
||||||
},
|
|
||||||
report_action
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check if report template is correct
|
|
||||||
report_html = self.env['report'].get_html(self.report, report_name)
|
|
||||||
self.assertRegexpMatches(report_html, 'Aged Partner Balance')
|
|
||||||
self.assertRegexpMatches(report_html, self.report.account_ids[0].name)
|
|
||||||
|
|
||||||
def test_03_generation_report_xlsx(self):
|
|
||||||
"""Check if report XLSX is correctly generated"""
|
|
||||||
|
|
||||||
report_name = 'account_financial_report_qweb.' \
|
|
||||||
'report_aged_partner_balance_xlsx'
|
|
||||||
# Check if returned report action is correct
|
|
||||||
report_action = self.report.print_report(xlsx_report=True)
|
|
||||||
self.assertDictContainsSubset(
|
|
||||||
{
|
|
||||||
'type': 'ir.actions.report.xml',
|
|
||||||
'report_name': report_name,
|
|
||||||
'report_type': 'xlsx',
|
|
||||||
},
|
|
||||||
report_action
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check if report template is correct
|
|
||||||
action_name = 'account_financial_report_qweb.' \
|
|
||||||
'action_report_aged_partner_balance_xlsx'
|
'action_report_aged_partner_balance_xlsx'
|
||||||
report_xlsx = self.env.ref(action_name).render_report(
|
|
||||||
self.report.ids,
|
def _getReportTitle(self):
|
||||||
report_name,
|
return 'Aged Partner Balance'
|
||||||
{'report_type': u'xlsx'}
|
|
||||||
)
|
def _getBaseFilters(self):
|
||||||
self.assertGreaterEqual(len(report_xlsx[0]), 1)
|
return {
|
||||||
self.assertEqual(report_xlsx[1], 'xlsx')
|
'date_at': time.strftime('%Y-12-31'),
|
||||||
|
'company_id': self.env.ref('base.main_company').id,
|
||||||
|
}
|
||||||
|
|
||||||
|
def _getAdditionalFiltersToBeTested(self):
|
||||||
|
return [
|
||||||
|
{'only_posted_moves': True},
|
||||||
|
{'show_move_line_details': True},
|
||||||
|
{'only_posted_moves': True, 'show_move_line_details': True},
|
||||||
|
]
|
||||||
|
|
|
@ -4,73 +4,49 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from openerp.tests.common import TransactionCase
|
from . import abstract_test
|
||||||
|
|
||||||
|
|
||||||
class TestGeneralLedger(TransactionCase):
|
class TestGeneralLedger(abstract_test.AbstractTest):
|
||||||
|
"""
|
||||||
|
Technical tests for General Ledger Report.
|
||||||
|
"""
|
||||||
|
|
||||||
def setUp(cls):
|
def _getReportModel(self):
|
||||||
super(TestGeneralLedger, cls).setUp()
|
return self.env['report_general_ledger_qweb']
|
||||||
env = cls.env
|
|
||||||
model = env['report_general_ledger_qweb']
|
|
||||||
main_company = env.ref('base.main_company')
|
|
||||||
|
|
||||||
cls.report = model.create({
|
def _getQwebReportName(self):
|
||||||
|
return 'account_financial_report_qweb.report_general_ledger_qweb'
|
||||||
|
|
||||||
|
def _getXlsxReportName(self):
|
||||||
|
return 'account_financial_report_qweb.report_general_ledger_xlsx'
|
||||||
|
|
||||||
|
def _getXlsxReportActionName(self):
|
||||||
|
return 'account_financial_report_qweb.' \
|
||||||
|
'action_report_general_ledger_xlsx'
|
||||||
|
|
||||||
|
def _getReportTitle(self):
|
||||||
|
return 'General Ledger'
|
||||||
|
|
||||||
|
def _getBaseFilters(self):
|
||||||
|
return {
|
||||||
'date_from': time.strftime('%Y-01-01'),
|
'date_from': time.strftime('%Y-01-01'),
|
||||||
'date_to': time.strftime('%Y-12-31'),
|
'date_to': time.strftime('%Y-12-31'),
|
||||||
'company_id': main_company.id,
|
'company_id': self.env.ref('base.main_company').id,
|
||||||
'fy_start_date': time.strftime('%Y-01-01'),
|
'fy_start_date': time.strftime('%Y-01-01'),
|
||||||
})
|
}
|
||||||
|
|
||||||
def test_01_compute_data(self):
|
def _getAdditionalFiltersToBeTested(self):
|
||||||
"""Check if data are computed"""
|
return [
|
||||||
self.report.compute_data_for_report()
|
{'only_posted_moves': True},
|
||||||
self.assertGreaterEqual(len(self.report.account_ids), 1)
|
{'hide_account_balance_at_0': True},
|
||||||
|
{'centralize': True},
|
||||||
def test_02_generation_report_qweb(self):
|
{'only_posted_moves': True, 'hide_account_balance_at_0': True},
|
||||||
"""Check if report PDF/HTML is correctly generated"""
|
{'only_posted_moves': True, 'centralize': True},
|
||||||
|
{'hide_account_balance_at_0': True, 'centralize': True},
|
||||||
report_name = 'account_financial_report_qweb.' \
|
|
||||||
'report_general_ledger_qweb'
|
|
||||||
# Check if returned report action is correct
|
|
||||||
report_action = self.report.print_report(xlsx_report=False)
|
|
||||||
self.assertDictContainsSubset(
|
|
||||||
{
|
{
|
||||||
'type': 'ir.actions.report.xml',
|
'only_posted_moves': True,
|
||||||
'report_name': report_name,
|
'hide_account_balance_at_0': True,
|
||||||
'report_type': 'qweb-pdf',
|
'centralize': True
|
||||||
},
|
},
|
||||||
report_action
|
]
|
||||||
)
|
|
||||||
|
|
||||||
# Check if report template is correct
|
|
||||||
report_html = self.env['report'].get_html(self.report, report_name)
|
|
||||||
self.assertRegexpMatches(report_html, 'General Ledger')
|
|
||||||
self.assertRegexpMatches(report_html, self.report.account_ids[0].name)
|
|
||||||
|
|
||||||
def test_03_generation_report_xlsx(self):
|
|
||||||
"""Check if report XLSX is correctly generated"""
|
|
||||||
|
|
||||||
report_name = 'account_financial_report_qweb.' \
|
|
||||||
'report_general_ledger_xlsx'
|
|
||||||
# Check if returned report action is correct
|
|
||||||
report_action = self.report.print_report(xlsx_report=True)
|
|
||||||
self.assertDictContainsSubset(
|
|
||||||
{
|
|
||||||
'type': 'ir.actions.report.xml',
|
|
||||||
'report_name': report_name,
|
|
||||||
'report_type': 'xlsx',
|
|
||||||
},
|
|
||||||
report_action
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check if report template is correct
|
|
||||||
action_name = 'account_financial_report_qweb.' \
|
|
||||||
'action_report_general_ledger_xlsx'
|
|
||||||
report_xlsx = self.env.ref(action_name).render_report(
|
|
||||||
self.report.ids,
|
|
||||||
report_name,
|
|
||||||
{'report_type': u'xlsx'}
|
|
||||||
)
|
|
||||||
self.assertGreaterEqual(len(report_xlsx[0]), 1)
|
|
||||||
self.assertEqual(report_xlsx[1], 'xlsx')
|
|
||||||
|
|
|
@ -4,71 +4,38 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from openerp.tests.common import TransactionCase
|
from . import abstract_test
|
||||||
|
|
||||||
|
|
||||||
class TestOpenItems(TransactionCase):
|
class TestOpenItems(abstract_test.AbstractTest):
|
||||||
|
"""
|
||||||
|
Technical tests for Open Items Report.
|
||||||
|
"""
|
||||||
|
|
||||||
def setUp(cls):
|
def _getReportModel(self):
|
||||||
super(TestOpenItems, cls).setUp()
|
return self.env['report_open_items_qweb']
|
||||||
env = cls.env
|
|
||||||
model = env['report_open_items_qweb']
|
|
||||||
main_company = env.ref('base.main_company')
|
|
||||||
|
|
||||||
cls.report = model.create({
|
def _getQwebReportName(self):
|
||||||
|
return 'account_financial_report_qweb.report_open_items_qweb'
|
||||||
|
|
||||||
|
def _getXlsxReportName(self):
|
||||||
|
return 'account_financial_report_qweb.report_open_items_xlsx'
|
||||||
|
|
||||||
|
def _getXlsxReportActionName(self):
|
||||||
|
return 'account_financial_report_qweb.action_report_open_items_xlsx'
|
||||||
|
|
||||||
|
def _getReportTitle(self):
|
||||||
|
return 'Open Items'
|
||||||
|
|
||||||
|
def _getBaseFilters(self):
|
||||||
|
return {
|
||||||
'date_at': time.strftime('%Y-12-31'),
|
'date_at': time.strftime('%Y-12-31'),
|
||||||
'company_id': main_company.id,
|
'company_id': self.env.ref('base.main_company').id,
|
||||||
})
|
}
|
||||||
|
|
||||||
def test_01_compute_data(self):
|
def _getAdditionalFiltersToBeTested(self):
|
||||||
"""Check if data are computed"""
|
return [
|
||||||
self.report.compute_data_for_report()
|
{'only_posted_moves': True},
|
||||||
self.assertGreaterEqual(len(self.report.account_ids), 1)
|
{'hide_account_balance_at_0': True},
|
||||||
|
{'only_posted_moves': True, 'hide_account_balance_at_0': True},
|
||||||
def test_02_generation_report_qweb(self):
|
]
|
||||||
"""Check if report PDF/HTML is correctly generated"""
|
|
||||||
|
|
||||||
report_name = 'account_financial_report_qweb.' \
|
|
||||||
'report_open_items_qweb'
|
|
||||||
# Check if returned report action is correct
|
|
||||||
report_action = self.report.print_report()
|
|
||||||
self.assertDictContainsSubset(
|
|
||||||
{
|
|
||||||
'type': 'ir.actions.report.xml',
|
|
||||||
'report_name': report_name,
|
|
||||||
'report_type': 'qweb-pdf',
|
|
||||||
},
|
|
||||||
report_action
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check if report template is correct
|
|
||||||
report_html = self.env['report'].get_html(self.report, report_name)
|
|
||||||
self.assertRegexpMatches(report_html, 'Open Items')
|
|
||||||
self.assertRegexpMatches(report_html, self.report.account_ids[0].name)
|
|
||||||
|
|
||||||
def test_03_generation_report_xlsx(self):
|
|
||||||
"""Check if report XLSX is correctly generated"""
|
|
||||||
|
|
||||||
report_name = 'account_financial_report_qweb.' \
|
|
||||||
'report_open_items_xlsx'
|
|
||||||
# Check if returned report action is correct
|
|
||||||
report_action = self.report.print_report(xlsx_report=True)
|
|
||||||
self.assertDictContainsSubset(
|
|
||||||
{
|
|
||||||
'type': 'ir.actions.report.xml',
|
|
||||||
'report_name': report_name,
|
|
||||||
'report_type': 'xlsx',
|
|
||||||
},
|
|
||||||
report_action
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check if report template is correct
|
|
||||||
action_name = 'account_financial_report_qweb.' \
|
|
||||||
'action_report_open_items_xlsx'
|
|
||||||
report_xlsx = self.env.ref(action_name).render_report(
|
|
||||||
self.report.ids,
|
|
||||||
report_name,
|
|
||||||
{'report_type': u'xlsx'}
|
|
||||||
)
|
|
||||||
self.assertGreaterEqual(len(report_xlsx[0]), 1)
|
|
||||||
self.assertEqual(report_xlsx[1], 'xlsx')
|
|
||||||
|
|
|
@ -4,73 +4,51 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from openerp.tests.common import TransactionCase
|
from . import abstract_test
|
||||||
|
|
||||||
|
|
||||||
class TestTrialBalance(TransactionCase):
|
class TestTrialBalance(abstract_test.AbstractTest):
|
||||||
|
"""
|
||||||
|
Technical tests for Trial Balance Report.
|
||||||
|
"""
|
||||||
|
|
||||||
def setUp(cls):
|
def _getReportModel(self):
|
||||||
super(TestTrialBalance, cls).setUp()
|
return self.env['report_trial_balance_qweb']
|
||||||
env = cls.env
|
|
||||||
model = env['report_trial_balance_qweb']
|
|
||||||
main_company = env.ref('base.main_company')
|
|
||||||
|
|
||||||
cls.report = model.create({
|
def _getQwebReportName(self):
|
||||||
|
return 'account_financial_report_qweb.report_trial_balance_qweb'
|
||||||
|
|
||||||
|
def _getXlsxReportName(self):
|
||||||
|
return 'account_financial_report_qweb.report_trial_balance_xlsx'
|
||||||
|
|
||||||
|
def _getXlsxReportActionName(self):
|
||||||
|
return 'account_financial_report_qweb.action_report_trial_balance_xlsx'
|
||||||
|
|
||||||
|
def _getReportTitle(self):
|
||||||
|
return 'Trial Balance'
|
||||||
|
|
||||||
|
def _getBaseFilters(self):
|
||||||
|
return {
|
||||||
'date_from': time.strftime('%Y-01-01'),
|
'date_from': time.strftime('%Y-01-01'),
|
||||||
'date_to': time.strftime('%Y-12-31'),
|
'date_to': time.strftime('%Y-12-31'),
|
||||||
'company_id': main_company.id,
|
'company_id': self.env.ref('base.main_company').id,
|
||||||
'fy_start_date': time.strftime('%Y-01-01'),
|
'fy_start_date': time.strftime('%Y-01-01'),
|
||||||
})
|
}
|
||||||
|
|
||||||
def test_01_compute_data(self):
|
def _getAdditionalFiltersToBeTested(self):
|
||||||
"""Check if data are computed"""
|
return [
|
||||||
self.report.compute_data_for_report()
|
{'only_posted_moves': True},
|
||||||
self.assertGreaterEqual(len(self.report.account_ids), 1)
|
{'hide_account_balance_at_0': True},
|
||||||
|
{'show_partner_details': True},
|
||||||
def test_02_generation_report_qweb(self):
|
{'only_posted_moves': True, 'hide_account_balance_at_0': True},
|
||||||
"""Check if report PDF/HTML is correctly generated"""
|
{'only_posted_moves': True, 'show_partner_details': True},
|
||||||
|
{'hide_account_balance_at_0': True, 'show_partner_details': True},
|
||||||
report_name = 'account_financial_report_qweb.' \
|
|
||||||
'report_trial_balance_qweb'
|
|
||||||
# Check if returned report action is correct
|
|
||||||
report_action = self.report.print_report(xlsx_report=False)
|
|
||||||
self.assertDictContainsSubset(
|
|
||||||
{
|
{
|
||||||
'type': 'ir.actions.report.xml',
|
'only_posted_moves': True,
|
||||||
'report_name': report_name,
|
'hide_account_balance_at_0': True,
|
||||||
'report_type': 'qweb-pdf',
|
'show_partner_details': True
|
||||||
},
|
},
|
||||||
report_action
|
]
|
||||||
)
|
|
||||||
|
|
||||||
# Check if report template is correct
|
def _partner_test_is_possible(self, filters):
|
||||||
report_html = self.env['report'].get_html(self.report, report_name)
|
return 'show_partner_details' in filters
|
||||||
self.assertRegexpMatches(report_html, 'Trial Balance')
|
|
||||||
self.assertRegexpMatches(report_html, self.report.account_ids[0].name)
|
|
||||||
|
|
||||||
def test_03_generation_report_xlsx(self):
|
|
||||||
"""Check if report XLSX is correctly generated"""
|
|
||||||
|
|
||||||
report_name = 'account_financial_report_qweb.' \
|
|
||||||
'report_trial_balance_xlsx'
|
|
||||||
# Check if returned report action is correct
|
|
||||||
report_action = self.report.print_report(xlsx_report=True)
|
|
||||||
self.assertDictContainsSubset(
|
|
||||||
{
|
|
||||||
'type': 'ir.actions.report.xml',
|
|
||||||
'report_name': report_name,
|
|
||||||
'report_type': 'xlsx',
|
|
||||||
},
|
|
||||||
report_action
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check if report template is correct
|
|
||||||
action_name = 'account_financial_report_qweb.' \
|
|
||||||
'action_report_trial_balance_xlsx'
|
|
||||||
report_xlsx = self.env.ref(action_name).render_report(
|
|
||||||
self.report.ids,
|
|
||||||
report_name,
|
|
||||||
{'report_type': u'xlsx'}
|
|
||||||
)
|
|
||||||
self.assertGreaterEqual(len(report_xlsx[0]), 1)
|
|
||||||
self.assertEqual(report_xlsx[1], 'xlsx')
|
|
||||||
|
|
Loading…
Reference in New Issue