fix(exporter): Count for child table filters
- Extract count method from list_view.js for reuse
This commit is contained in:
parent
b502bfff07
commit
bbdc5e0db8
3 changed files with 27 additions and 31 deletions
|
|
@ -285,11 +285,9 @@ frappe.data_import.DataExporter = class DataExporter {
|
|||
}
|
||||
|
||||
get_filters() {
|
||||
return this.filter_group.get_filters().reduce((acc, filter) => {
|
||||
return Object.assign(acc, {
|
||||
[filter[1]]: [filter[2], filter[3]]
|
||||
});
|
||||
}, {});
|
||||
return this.filter_group.get_filters().map(filter => {
|
||||
return filter.slice(0, 4)
|
||||
});
|
||||
}
|
||||
|
||||
get_multicheck_options(doctype, child_fieldname = null) {
|
||||
|
|
|
|||
|
|
@ -91,12 +91,26 @@ frappe.db = {
|
|||
});
|
||||
},
|
||||
count: function(doctype, args={}) {
|
||||
return new Promise(resolve => {
|
||||
frappe.call({
|
||||
method: 'frappe.client.get_count',
|
||||
type: 'GET',
|
||||
args: Object.assign(args, { doctype })
|
||||
}).then(r => resolve(r.message));
|
||||
let filters = args.filters || {};
|
||||
const with_child_table_filter = Array.isArray(filters) && filters.some(filter => {
|
||||
return filter[0] !== doctype;
|
||||
});
|
||||
|
||||
const fields = [
|
||||
// cannot break this line as it adds extra \n's and \t's which breaks the query
|
||||
`count(${with_child_table_filter ? 'distinct': ''} ${frappe.model.get_full_column_name('name', doctype)}) AS total_count`
|
||||
];
|
||||
|
||||
return frappe.call({
|
||||
type: 'GET',
|
||||
method: 'frappe.desk.reportview.get',
|
||||
args: {
|
||||
doctype,
|
||||
filters,
|
||||
fields,
|
||||
}
|
||||
}).then(r => {
|
||||
return r.message.values[0][0];
|
||||
});
|
||||
},
|
||||
get_link_options(doctype, txt = '', filters={}) {
|
||||
|
|
|
|||
|
|
@ -760,26 +760,10 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
|
|||
let current_count = this.data.length;
|
||||
let count_without_children = this.data.uniqBy(d => d.name).length;
|
||||
|
||||
const filters = this.get_filters_for_args();
|
||||
const with_child_table_filter = filters.some(filter => {
|
||||
return filter[0] !== this.doctype;
|
||||
});
|
||||
|
||||
const fields = [
|
||||
// cannot break this line as it adds extra \n's and \t's which breaks the query
|
||||
`count(${with_child_table_filter ? 'distinct': ''}${frappe.model.get_full_column_name('name', this.doctype)}) AS total_count`
|
||||
];
|
||||
|
||||
return frappe.call({
|
||||
type: 'GET',
|
||||
method: this.method,
|
||||
args: {
|
||||
doctype: this.doctype,
|
||||
filters,
|
||||
fields,
|
||||
}
|
||||
}).then(r => {
|
||||
this.total_count = r.message.values[0][0] || current_count;
|
||||
return frappe.db.count(this.doctype, {
|
||||
filters: this.get_filters_for_args()
|
||||
}).then(total_count => {
|
||||
this.total_count = total_count || current_count;
|
||||
let str = __('{0} of {1}', [current_count, this.total_count]);
|
||||
if (count_without_children !== current_count) {
|
||||
str = __('{0} of {1} ({2} rows with children)', [count_without_children, this.total_count, current_count]);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue