@@ -76,8 +102,8 @@ frappe.ui.GroupBy = class {
}
apply_group_by() {
- this.group_by = this.page.wrapper.find('.groupby option:selected').val();
- this.aggregate_function = this.page.wrapper.find('.aggregate-function option:selected').val();
+ this.group_by = this.groupby_select.val();
+ this.aggregate_function = this.aggregate_function_select.val();
if (this.aggregate_function === 'count') {
this.aggregate_on = 'name';
@@ -101,6 +127,10 @@ frappe.ui.GroupBy = class {
//If function is count add a new field for count
this.page.wrapper.find('.set-groupby-and-run').hide();
+ }
+
+ apply_group_by_and_refresh() {
+ this.apply_group_by();
this.report_view.refresh();
}
@@ -194,4 +224,5 @@ frappe.ui.GroupBy = class {
get_group_by_fields() {
return this.report_view.meta.fields.filter((f)=> ["Select", "Link"].includes(f.fieldtype));
}
+
};
diff --git a/frappe/public/js/frappe/views/reports/report_view.js b/frappe/public/js/frappe/views/reports/report_view.js
index c4bce82249..fa352269b9 100644
--- a/frappe/public/js/frappe/views/reports/report_view.js
+++ b/frappe/public/js/frappe/views/reports/report_view.js
@@ -20,8 +20,6 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
this.report_name = route[3];
}
- this.add_totals_row = this.view_user_settings.add_totals_row || 0;
-
if (this.report_name) {
return this.get_report_doc()
.then(doc => {
@@ -35,6 +33,8 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
this.page_length = this.report_doc.json.page_length || 20;
this.order_by = this.report_doc.json.order_by || 'modified desc';
});
+ } else {
+ this.add_totals_row = this.view_user_settings.add_totals_row || 0;
}
}
@@ -70,6 +70,13 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
//Setup groupby for reports
this.group_by_control = new frappe.ui.GroupBy(this);
+ if (this.report_doc && this.report_doc.json.group_by) {
+ this.group_by_control.apply_settings(this.report_doc.json.group_by);
+ }
+ if (this.view_user_settings && this.view_user_settings.group_by) {
+ this.group_by_control.apply_settings(this.view_user_settings.group_by);
+ }
+
}
get_args() {
@@ -102,7 +109,8 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
order_by: this.sort_selector.get_sql_string(),
add_totals_row: this.add_totals_row,
page_length: this.page_length,
- column_widths: this.get_column_widths()
+ column_widths: this.get_column_widths(),
+ group_by: this.group_by_control.get_settings()
}
let report_settings = {
@@ -111,7 +119,8 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
order_by: this.report_doc.json.order_by,
add_totals_row: this.report_doc.json.add_totals_row,
page_length: this.report_doc.json.page_length,
- column_widths: this.report_doc.json.column_widths
+ column_widths: this.report_doc.json.column_widths,
+ group_by: this.report_doc.json.group_by
}
if (!frappe.utils.deep_equal(current_settings, report_settings)) {
@@ -129,7 +138,7 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
fields: this.fields,
filters: this.filter_area.get(),
order_by: this.sort_selector.get_sql_string(),
- group_by: this.group_by,
+ group_by: this.group_by_control.get_settings(),
add_totals_row: this.add_totals_row
});
}
@@ -997,7 +1006,8 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
order_by: this.sort_selector.get_sql_string(),
add_totals_row: this.add_totals_row,
page_length: this.page_length,
- column_widths: this.get_column_widths()
+ column_widths: this.get_column_widths(),
+ group_by: this.group_by_control.get_settings()
}
return frappe.call({