refactor: filter on name while fetching custom column (#22133)
This commit is contained in:
parent
3784ce8507
commit
08d5b59778
2 changed files with 18 additions and 4 deletions
|
|
@ -459,12 +459,16 @@ def add_total_row(result, columns, meta=None, is_tree=False, parent_field=None):
|
|||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_data_for_custom_field(doctype, field):
|
||||
def get_data_for_custom_field(doctype, field, names=None):
|
||||
|
||||
if not frappe.has_permission(doctype, "read"):
|
||||
frappe.throw(_("Not Permitted to read {0}").format(doctype), frappe.PermissionError)
|
||||
|
||||
return frappe._dict(frappe.get_all(doctype, fields=["name", field], as_list=1))
|
||||
filters = {}
|
||||
if names:
|
||||
filters.update({"name": ["in", json.loads(names)]})
|
||||
|
||||
return frappe._dict(frappe.get_list(doctype, filters=filters, fields=["name", field], as_list=1))
|
||||
|
||||
|
||||
def get_data_for_custom_report(columns):
|
||||
|
|
|
|||
|
|
@ -1697,10 +1697,14 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
args: {
|
||||
field: values.field,
|
||||
doctype: values.doctype,
|
||||
names: Array.from(
|
||||
this.doctype_field_map[values.doctype].names
|
||||
),
|
||||
},
|
||||
callback: (r) => {
|
||||
const custom_data = r.message;
|
||||
const link_field = this.doctype_field_map[values.doctype];
|
||||
const link_field =
|
||||
this.doctype_field_map[values.doctype].fieldname;
|
||||
|
||||
this.add_custom_column(
|
||||
custom_columns,
|
||||
|
|
@ -1838,7 +1842,13 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
);
|
||||
|
||||
doctypes.forEach((doc) => {
|
||||
this.doctype_field_map[doc.doctype] = doc.fieldname;
|
||||
this.doctype_field_map[doc.doctype] = { fieldname: doc.fieldname, names: new Set() };
|
||||
});
|
||||
|
||||
this.data.forEach((row) => {
|
||||
doctypes.forEach((doc) => {
|
||||
this.doctype_field_map[doc.doctype].names.add(row[doc.fieldname]);
|
||||
});
|
||||
});
|
||||
|
||||
return doctypes;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue