Merge pull request #9278 from ruchamahabal/add_status_to_pick_columns
feat(Report View): show status field derived from docstatus or workflow if not in docfields
This commit is contained in:
commit
3f308c7fc7
2 changed files with 63 additions and 15 deletions
|
|
@ -19,11 +19,13 @@ context('Report View', () => {
|
|||
cy.server();
|
||||
cy.route('POST', 'api/method/frappe.client.set_value').as('value-update');
|
||||
cy.visit(`/desk#List/${doctype_name}/Report`);
|
||||
let cell = cy.get('.dt-row-0 > .dt-cell--col-3');
|
||||
// check status column added from docstatus
|
||||
cy.get('.dt-row-0 > .dt-cell--col-3').should('contain', 'Submitted');
|
||||
let cell = cy.get('.dt-row-0 > .dt-cell--col-4');
|
||||
// select the cell
|
||||
cell.dblclick();
|
||||
cell.find('input[data-fieldname="enabled"]').check({force: true});
|
||||
cy.get('.dt-row-0 > .dt-cell--col-4').click();
|
||||
cy.get('.dt-row-0 > .dt-cell--col-5').click();
|
||||
cy.wait('@value-update');
|
||||
cy.get('@doc').then(doc => {
|
||||
cy.call('frappe.client.get_value', {
|
||||
|
|
|
|||
|
|
@ -684,7 +684,6 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
|
|||
}
|
||||
|
||||
build_fields() {
|
||||
this.fields.push(['docstatus', this.doctype]);
|
||||
super.build_fields();
|
||||
}
|
||||
|
||||
|
|
@ -742,6 +741,16 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
|
|||
}
|
||||
}
|
||||
|
||||
add_status_dependency_column(col, doctype) {
|
||||
// Adds dependent column from which status is derived if required
|
||||
if (!this.fields.find(f => f[0] === col)) {
|
||||
const field = [col, doctype];
|
||||
this.fields.push(field);
|
||||
this.refresh();
|
||||
frappe.show_alert(__('Also adding the status dependency field {0}', [field[0].bold()]));
|
||||
}
|
||||
}
|
||||
|
||||
remove_column_from_datatable(column) {
|
||||
const index = this.fields.findIndex(f => column.field === f[0]);
|
||||
if (index === -1) return;
|
||||
|
|
@ -778,12 +787,24 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
|
|||
|
||||
let doctype_fields = frappe.meta.get_docfields(this.doctype).filter(standard_fields_filter);
|
||||
|
||||
// filter out docstatus field from picker
|
||||
let std_fields = frappe.model.std_fields.filter( df => df.fieldname !== 'docstatus');
|
||||
|
||||
// add status field derived from docstatus, if status is not a standard field
|
||||
if (!frappe.meta.has_field(this.doctype, 'status')) {
|
||||
doctype_fields = [{
|
||||
label: __('Status'),
|
||||
fieldname: 'docstatus',
|
||||
fieldtype: 'Data'
|
||||
}].concat(doctype_fields);
|
||||
}
|
||||
|
||||
doctype_fields = [{
|
||||
label: __('ID'),
|
||||
fieldname: 'name',
|
||||
fieldtype: 'Data',
|
||||
reqd: 1
|
||||
}].concat(doctype_fields, frappe.model.std_fields);
|
||||
}].concat(doctype_fields, std_fields);
|
||||
|
||||
out[this.doctype] = doctype_fields;
|
||||
|
||||
|
|
@ -858,16 +879,23 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
|
|||
this.columns_map = {};
|
||||
|
||||
for (let f of this.fields) {
|
||||
let column;
|
||||
if (f[0]!=='docstatus') {
|
||||
let column = this.build_column(f);
|
||||
if (column) {
|
||||
if (column_widths) {
|
||||
column.width = column_widths[column.id] || column.width || 120;
|
||||
}
|
||||
this.columns.push(column);
|
||||
this.columns_map[column.id] = column;
|
||||
column = this.build_column(f);
|
||||
} else {
|
||||
// if status is not in fields append status column derived from docstatus
|
||||
if (!this.fields.includes(['status', this.doctype]) && !frappe.meta.has_field(this.doctype, 'status')) {
|
||||
column = this.build_column(['docstatus', this.doctype]);
|
||||
}
|
||||
}
|
||||
|
||||
if (column) {
|
||||
if (column_widths) {
|
||||
column.width = column_widths[column.id] || column.width || 120;
|
||||
}
|
||||
this.columns.push(column);
|
||||
this.columns_map[column.id] = column;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -892,9 +920,14 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
|
|||
}
|
||||
}
|
||||
docfield.parent = this.doctype;
|
||||
if (fieldname == "name") {
|
||||
if (fieldname == 'name') {
|
||||
docfield.options = this.doctype;
|
||||
}
|
||||
if (fieldname == 'docstatus' && !frappe.meta.has_field(this.doctype, 'status')) {
|
||||
docfield.label = 'Status';
|
||||
docfield.fieldtype = 'Data';
|
||||
docfield.name = 'status';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!docfield) return;
|
||||
|
|
@ -982,7 +1015,6 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
|
|||
totals_row[0].content = __('Totals').bold();
|
||||
out.push(totals_row);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
@ -1003,8 +1035,22 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (col.field in d) {
|
||||
if (col.field === 'docstatus' && !frappe.meta.has_field(this.doctype, 'status')) {
|
||||
// get status from docstatus
|
||||
let status = frappe.get_indicator(d, this.doctype);
|
||||
if (!status[0]) {
|
||||
// get_indicator returns the dependent field's condition as the 3rd parameter
|
||||
let dependent_col = status[2].split(',')[0];
|
||||
// add status dependency column
|
||||
this.add_status_dependency_column(dependent_col, this.doctype);
|
||||
}
|
||||
return {
|
||||
name: d.name,
|
||||
doctype: col.docfield.parent,
|
||||
content: status[0],
|
||||
editable: false
|
||||
};
|
||||
} else if (col.field in d) {
|
||||
const value = d[col.field];
|
||||
return {
|
||||
name: d.name,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue