test: account reports
This commit is contained in:
parent
2d76c05175
commit
f195f803ff
48
erpnext/accounts/test/test_reports.py
Normal file
48
erpnext/accounts/test/test_reports.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import unittest
|
||||||
|
from typing import List, Tuple
|
||||||
|
|
||||||
|
from erpnext.tests.utils import ReportFilters, ReportName, execute_script_report
|
||||||
|
|
||||||
|
DEFAULT_FILTERS = {
|
||||||
|
"company": "_Test Company",
|
||||||
|
"from_date": "2010-01-01",
|
||||||
|
"to_date": "2030-01-01",
|
||||||
|
"period_start_date": "2010-01-01",
|
||||||
|
"period_end_date": "2030-01-01"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
REPORT_FILTER_TEST_CASES: List[Tuple[ReportName, ReportFilters]] = [
|
||||||
|
("General Ledger", {"group_by": "Group by Voucher (Consolidated)"} ),
|
||||||
|
("General Ledger", {"group_by": "Group by Voucher (Consolidated)", "include_dimensions": 1} ),
|
||||||
|
("Accounts Payable", {"range1": 30, "range2": 60, "range3": 90, "range4": 120}),
|
||||||
|
("Accounts Receivable", {"range1": 30, "range2": 60, "range3": 90, "range4": 120}),
|
||||||
|
("Consolidated Financial Statement", {"report": "Balance Sheet"} ),
|
||||||
|
("Consolidated Financial Statement", {"report": "Profit and Loss Statement"} ),
|
||||||
|
("Consolidated Financial Statement", {"report": "Cash Flow"} ),
|
||||||
|
("Gross Profit", {"group_by": "Invoice"}),
|
||||||
|
("Gross Profit", {"group_by": "Item Code"}),
|
||||||
|
("Gross Profit", {"group_by": "Item Group"}),
|
||||||
|
("Gross Profit", {"group_by": "Customer"}),
|
||||||
|
("Gross Profit", {"group_by": "Customer Group"}),
|
||||||
|
("Item-wise Sales Register", {}),
|
||||||
|
("Item-wise Purchase Register", {}),
|
||||||
|
("Sales Register", {}),
|
||||||
|
("Purchase Register", {}),
|
||||||
|
("Tax Detail", {"mode": "run", "report_name": "Tax Detail"},),
|
||||||
|
]
|
||||||
|
|
||||||
|
OPTIONAL_FILTERS = {}
|
||||||
|
|
||||||
|
|
||||||
|
class TestReports(unittest.TestCase):
|
||||||
|
def test_execute_all_accounts_reports(self):
|
||||||
|
"""Test that all script report in stock modules are executable with supported filters"""
|
||||||
|
for report, filter in REPORT_FILTER_TEST_CASES:
|
||||||
|
execute_script_report(
|
||||||
|
report_name=report,
|
||||||
|
module="Accounts",
|
||||||
|
filters=filter,
|
||||||
|
default_filters=DEFAULT_FILTERS,
|
||||||
|
optional_filters=OPTIONAL_FILTERS if filter.get("_optional") else None,
|
||||||
|
)
|
@ -125,17 +125,23 @@ def execute_script_report(
|
|||||||
if default_filters is None:
|
if default_filters is None:
|
||||||
default_filters = {}
|
default_filters = {}
|
||||||
|
|
||||||
|
test_filters = []
|
||||||
report_execute_fn = frappe.get_attr(get_report_module_dotted_path(module, report_name) + ".execute")
|
report_execute_fn = frappe.get_attr(get_report_module_dotted_path(module, report_name) + ".execute")
|
||||||
report_filters = frappe._dict(default_filters).copy().update(filters)
|
report_filters = frappe._dict(default_filters).copy().update(filters)
|
||||||
|
|
||||||
report_data = report_execute_fn(report_filters)
|
test_filters.append(report_filters)
|
||||||
|
|
||||||
if optional_filters:
|
if optional_filters:
|
||||||
for key, value in optional_filters.items():
|
for key, value in optional_filters.items():
|
||||||
filter_with_optional_param = report_filters.copy().update({key: value})
|
test_filters.append(report_filters.copy().update({key: value}))
|
||||||
report_execute_fn(filter_with_optional_param)
|
|
||||||
|
for test_filter in test_filters:
|
||||||
|
try:
|
||||||
|
report_execute_fn(test_filter)
|
||||||
|
except Exception:
|
||||||
|
print(f"Report failed to execute with filters: {test_filter}")
|
||||||
|
raise
|
||||||
|
|
||||||
return report_data
|
|
||||||
|
|
||||||
|
|
||||||
def timeout(seconds=30, error_message="Test timed out."):
|
def timeout(seconds=30, error_message="Test timed out."):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user