fix(goal): improve validation (#35186)
This commit is contained in:
parent
ff3ada7030
commit
ec615fe9aa
1 changed files with 12 additions and 0 deletions
|
|
@ -20,6 +20,17 @@ def get_monthly_results(
|
|||
) -> dict:
|
||||
"""Get monthly aggregation values for given field of doctype"""
|
||||
|
||||
# Only allow some valid aggregations
|
||||
if aggregation.lower() not in {"sum", "avg", "count", "min", "max"}:
|
||||
frappe.throw(f"Invalid aggregation type: {aggregation}")
|
||||
|
||||
# Check that the goal and date fields exist on the chosen doctype
|
||||
valid_fields = frappe.get_meta(goal_doctype).get_valid_fields()
|
||||
if goal_field not in valid_fields:
|
||||
frappe.throw(f"Invalid goal field: {goal_field}")
|
||||
if date_col not in valid_fields:
|
||||
frappe.throw(f"Invalid date field: {date_col}")
|
||||
|
||||
Table = DocType(goal_doctype)
|
||||
date_format = "%m-%Y" if frappe.db.db_type != "postgres" else "MM-YYYY"
|
||||
|
||||
|
|
@ -32,6 +43,7 @@ def get_monthly_results(
|
|||
],
|
||||
filters=filters,
|
||||
validate_filters=True,
|
||||
ignore_permissions=False,
|
||||
)
|
||||
.groupby("month_year")
|
||||
.run()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue