fix: works for multiple rows now after saving

This commit is contained in:
RitvikSardana 2023-09-14 13:23:00 +05:30
parent 985b9a4ac4
commit d3178527b3
2 changed files with 21 additions and 20 deletions

View file

@ -101,13 +101,6 @@ def generate_report_result(
report_custom_columns = [
column for column in columns if column["fieldname"] not in report_column_names
]
# for column in report_custom_columns:
# column["fieldname"] = column["fieldname"].split("-")[0]
# for column in columns:
# if (len(column.get("fieldname").split("-")) > 1):
# print(column.get("fieldname"))
# column["fieldname"] = column["fieldname"].split("-")[0]
if report_custom_columns:
result = add_custom_column_data(report_custom_columns, result)
@ -118,7 +111,6 @@ def generate_report_result(
if cint(report.add_total_row) and result and not skip_total_row:
result = add_total_row(result, columns, is_tree=is_tree, parent_field=parent_field)
# breakpoint()
return {
"result": result,
"columns": columns,
@ -231,7 +223,11 @@ def run(
def add_custom_column_data(custom_columns, result):
doctype_name_from_custom_field = []
for column in custom_columns:
doctype_name_from_custom_field.append(frappe.unscrub(column["fieldname"].split("-")[1])) if len(
column["fieldname"].split("-")
) > 1 else None
column["fieldname"] = column["fieldname"].split("-")[0]
custom_column_data = get_data_for_custom_report(custom_columns, result)
@ -251,8 +247,10 @@ def add_custom_column_data(custom_columns, result):
# possible if the row is empty
if not row_reference:
continue
if custom_column_data.get(key).get(row_reference) is None:
if (
custom_column_data.get(key).get(row_reference) is None
and key[0] in doctype_name_from_custom_field
):
column["fieldname"] = column.get("fieldname") + "-" + frappe.unscrub(key[0])
row[column.get("fieldname")] = custom_column_data.get(key).get(row_reference)

View file

@ -933,10 +933,7 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
render_datatable() {
let data = this.data;
console.log(this.data);
let columns = this.columns.filter((col) => !col.hidden);
// columns = this.
// debugger
if (this.raw_data.add_total_row && !this.report_settings.tree) {
data = data.slice();
@ -1683,8 +1680,13 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
const insert_after_index = this.columns.findIndex(
(column) => column.label === values.insert_after
);
custom_columns.push({
fieldname: df.fieldname + "-" + frappe.scrub(values.doctype),
fieldname: this.columns
.map((column) => column.fieldname)
.includes(df.fieldname)
? df.fieldname + "-" + frappe.scrub(values.doctype)
: df.fieldname,
fieldtype: df.fieldtype,
label: df.label,
insert_after_index: insert_after_index,
@ -1706,10 +1708,8 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
},
callback: (r) => {
const custom_data = r.message;
console.log(r.message);
const link_field =
this.doctype_field_map[values.doctype].fieldname;
console.log(link_field, values.field);
this.add_custom_column(
custom_columns,
custom_data,
@ -1802,15 +1802,18 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
new_column_data,
insert_after_index
) {
console.log(custom_column);
const column = this.prepare_columns(custom_column);
const column_field = new_column_data.field;
this.columns.splice(insert_after_index + 1, 0, column[0]);
this.data.forEach((row) => {
console.log(row);
row[column_field + "-" + frappe.scrub(new_column_data.doctype)] =
custom_data[row[link_field]];
if (column[0].fieldname.includes("-")) {
row[column_field + "-" + frappe.scrub(new_column_data.doctype)] =
custom_data[row[link_field]];
} else {
row[column_field] = custom_data[row[link_field]];
}
});
this.render_datatable();