fix: pass fields explicitly
- to prevent addition of default `name` field - also, add fields only if it is a select query
This commit is contained in:
parent
35c2654f00
commit
f982439eb9
3 changed files with 19 additions and 16 deletions
|
|
@ -236,16 +236,16 @@ class Engine:
|
|||
self.query = frappe.qb.from_(self.table).delete()
|
||||
else:
|
||||
self.query = frappe.qb.from_(self.table)
|
||||
# add fields
|
||||
self.fields = self.parse_fields(fields)
|
||||
if not self.fields:
|
||||
self.fields = [getattr(self.table, pluck or "name")]
|
||||
|
||||
self.fields = self.parse_fields(fields)
|
||||
if not self.fields:
|
||||
self.fields = [getattr(self.table, pluck or "name")]
|
||||
|
||||
for field in self.fields:
|
||||
if isinstance(field, DynamicTableField):
|
||||
self.query = field.apply_select(self.query)
|
||||
else:
|
||||
self.query = self.query.select(field)
|
||||
for field in self.fields:
|
||||
if isinstance(field, DynamicTableField):
|
||||
self.query = field.apply_select(self.query)
|
||||
else:
|
||||
self.query = self.query.select(field)
|
||||
|
||||
self.apply_filters(filters)
|
||||
self.apply_implicit_joins()
|
||||
|
|
|
|||
|
|
@ -119,9 +119,9 @@ class Cast_(Function):
|
|||
|
||||
def _aggregate(function, dt, fieldname, filters, **kwargs):
|
||||
return (
|
||||
frappe.qb.get_query(dt, filters=filters)
|
||||
.select(function(PseudoColumn(fieldname)))
|
||||
.run(**kwargs)[0][0]
|
||||
frappe.qb.get_query(dt, filters=filters, fields=[function(PseudoColumn(fieldname))]).run(
|
||||
**kwargs
|
||||
)[0][0]
|
||||
or 0
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -24,10 +24,13 @@ def get_monthly_results(
|
|||
date_format = "%m-%Y" if frappe.db.db_type != "postgres" else "MM-YYYY"
|
||||
|
||||
return dict(
|
||||
frappe.qb.get_query(table=goal_doctype, filters=filters)
|
||||
.select(
|
||||
DateFormat(Table[date_col], date_format).as_("month_year"),
|
||||
Function(aggregation, goal_field),
|
||||
frappe.qb.get_query(
|
||||
table=goal_doctype,
|
||||
fields=[
|
||||
DateFormat(Table[date_col], date_format).as_("month_year"),
|
||||
Function(aggregation, goal_field),
|
||||
],
|
||||
filters=filters,
|
||||
)
|
||||
.groupby("month_year")
|
||||
.run()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue