fix: pass parameters as list (#6626)
* fix: pass parameters as list * test: Add test case * test: Add json file for test data
This commit is contained in:
parent
50ad6bcdf6
commit
b247cae12e
3 changed files with 33 additions and 1 deletions
|
|
@ -149,7 +149,7 @@ class Report(Document):
|
|||
if params.get('sort_by'):
|
||||
order_by = _format(params.get('sort_by').split('.')) + ' ' + params.get('sort_order')
|
||||
else:
|
||||
order_by = _format(self.ref_doctype, 'modified') + ' desc'
|
||||
order_by = _format([self.ref_doctype, 'modified']) + ' desc'
|
||||
|
||||
if params.get('sort_by_next'):
|
||||
order_by += ', ' + _format(params.get('sort_by_next').split('.')) + ' ' + params.get('sort_order_next')
|
||||
|
|
|
|||
|
|
@ -53,3 +53,18 @@ class TestReport(unittest.TestCase):
|
|||
report = frappe.get_doc('Report', 'Test Report')
|
||||
|
||||
self.assertNotEquals(report.is_permitted(), True)
|
||||
|
||||
# test for the `_format` method if report data doesn't have sort_by parameter
|
||||
def test_format_method(self):
|
||||
if frappe.db.exists('Report', 'User Activity Report Without Sort'):
|
||||
frappe.delete_doc('Report', 'User Activity Report Without Sort')
|
||||
with open(os.path.join(os.path.dirname(__file__), 'user_activity_report_without_sort.json'), 'r') as f:
|
||||
frappe.get_doc(json.loads(f.read())).insert()
|
||||
|
||||
report = frappe.get_doc('Report', 'User Activity Report Without Sort')
|
||||
# this would raise an error without the fix added along with this test case
|
||||
columns, data = report.get_data()
|
||||
self.assertEqual(columns[0].get('label'), 'ID')
|
||||
self.assertEqual(columns[1].get('label'), 'User Type')
|
||||
self.assertTrue('Administrator' in [d[0] for d in data])
|
||||
frappe.delete_doc('Report', 'User Activity Report Without Sort')
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"add_total_row": 0,
|
||||
"apply_user_permissions": 1,
|
||||
"disabled": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "Report",
|
||||
"is_standard": "No",
|
||||
"javascript": null,
|
||||
"json": "{\"filters\":[],\"columns\":[[\"name\",\"User\"],[\"user_type\",\"User\"],[\"first_name\",\"User\"],[\"last_name\",\"User\"],[\"last_active\",\"User\"],[\"role\",\"Has Role\"]],\"sort_order\":\"desc\",\"sort_by_next\":null,\"sort_order_next\":\"desc\"}",
|
||||
"modified": "2018-12-17 18:27:07.728890",
|
||||
"module": "Core",
|
||||
"name": "User Activity Report Without Sort",
|
||||
"query": null,
|
||||
"ref_doctype": "User",
|
||||
"report_name": "User Activity Report Without Sort",
|
||||
"report_type": "Report Builder"
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue