fix: Set dependant property of grid fields while rendering (#16548)

This commit is contained in:
Shariq Ansari 2022-04-18 17:31:36 +05:30 committed by GitHub
parent 803f1fb061
commit de8f066dce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -595,6 +595,8 @@ export default class GridRow {
// to get update df for the row
let df = this.docfields.find(field => field.fieldname === col[0].fieldname);
this.set_dependant_property(df);
let colsize = col[1];
let txt = this.doc ?
frappe.format(this.doc[df.fieldname], df, null, this.doc) :
@ -633,6 +635,56 @@ export default class GridRow {
}
}
set_dependant_property(df) {
if (!df.reqd && df.mandatory_depends_on &&
this.evaluate_depends_on_value(df.mandatory_depends_on)) {
df.reqd = 1;
}
if (!df.read_only && df.read_only_depends_on &&
this.evaluate_depends_on_value(df.read_only_depends_on)) {
df.read_only = 1;
}
}
evaluate_depends_on_value(expression) {
let out = null;
let doc = this.doc;
if (!doc) return;
let parent = this.frm ? this.frm.doc : this.doc || null;
if (typeof (expression) === 'boolean') {
out = expression;
} else if (typeof (expression) === 'function') {
out = expression(doc);
} else if (expression.substr(0, 5)=='eval:') {
try {
out = frappe.utils.eval(expression.substr(5), { doc, parent });
if (parent && parent.istable && expression.includes('is_submittable')) {
out = true;
}
} catch (e) {
frappe.throw(__('Invalid "depends_on" expression'));
}
} else if (expression.substr(0, 3)=='fn:' && this.frm) {
out = this.frm.script_manager.trigger(expression.substr(3), this.doctype, this.docname);
} else {
var value = doc[expression];
if ($.isArray(value)) {
out = !!value.length;
} else {
out = !!value;
}
}
return out;
}
show_search_row() {
// show or remove search columns based on grid rows
this.show_search = this.frm && this.frm.doc &&