feat: flesh out boilerplate for script report (#27301)

This commit is contained in:
Raffael Meyer 2024-08-08 11:32:56 +02:00 committed by GitHub
parent 71eb3704bd
commit e57ca79783
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 52 additions and 5 deletions

View file

@ -2,7 +2,12 @@
// For license information, please see license.txt
frappe.query_reports["{name}"] = {{
"filters": [
]
filters: [
// {{
// "fieldname": "my_filter",
// "label": __("My Filter"),
// "fieldtype": "Data",
// "reqd": 1,
// }},
],
}};

View file

@ -2,8 +2,47 @@
# For license information, please see license.txt
# import frappe
from frappe import _
def execute(filters=None):
columns, data = [], []
def execute(filters: dict | None = None):
"""Return columns and data for the report.
This is the main entry point for the report. It accepts the filters as a
dictionary and should return columns and data. It is called by the framework
every time the report is refreshed or a filter is updated.
"""
columns = get_columns()
data = get_data()
return columns, data
def get_columns() -> list[dict]:
"""Return columns for the report.
One field definition per column, just like a DocType field definition.
"""
return [
{{
"label": _("Column 1"),
"fieldname": "column_1",
"fieldtype": "Data",
}},
{{
"label": _("Column 2"),
"fieldname": "column_2",
"fieldtype": "Int",
}},
]
def get_data() -> list[list]:
"""Return data for the report.
The report data is a list of rows, with each row being a list of cell values.
"""
return [
["Row 1", 1],
["Row 2", 2],
]

View file

@ -112,6 +112,9 @@ freezegun = "~=1.2.2"
[tool.ruff]
line-length = 110
target-version = "py310"
exclude = [
"**/doctype/*/boilerplate/*.py" # boilerplate are template strings, not valid python
]
[tool.ruff.lint]
select = [