Merge pull request #37214 from sagarvora/fix/grid-row-docfield-contamination
fix: prevent docfield copy contamination across grid rows on deletion/reorder
This commit is contained in:
commit
067a6351b5
3 changed files with 15 additions and 25 deletions
|
|
@ -574,7 +574,7 @@ export default class Grid {
|
|||
let grid_row;
|
||||
if (this.grid_rows[ri] && !append_row) {
|
||||
grid_row = this.grid_rows[ri];
|
||||
grid_row.doc = d;
|
||||
grid_row.update_doc(d);
|
||||
grid_row.refresh();
|
||||
} else {
|
||||
grid_row = new GridRow({
|
||||
|
|
|
|||
|
|
@ -53,25 +53,20 @@ export default class GridRow {
|
|||
this.wrapper.appendTo(this.parent);
|
||||
}
|
||||
|
||||
set_docfields(update = false) {
|
||||
update_doc(doc) {
|
||||
const changed = !this.doc || this.doc !== doc;
|
||||
this.doc = doc;
|
||||
if (changed) this.set_docfields();
|
||||
}
|
||||
|
||||
set_docfields() {
|
||||
if (this.doc && this.parent_df.options) {
|
||||
frappe.meta.make_docfield_copy_for(
|
||||
this.docfields = frappe.meta.get_docfields(
|
||||
this.parent_df.options,
|
||||
this.doc.name,
|
||||
this.docfields
|
||||
null,
|
||||
this.grid.docfields
|
||||
);
|
||||
const docfields = frappe.meta.get_docfields(this.parent_df.options, this.doc.name);
|
||||
if (update) {
|
||||
// to maintain references
|
||||
this.docfields.forEach((df) => {
|
||||
Object.assign(
|
||||
df,
|
||||
docfields.find((d) => d.fieldname === df.fieldname)
|
||||
);
|
||||
});
|
||||
} else {
|
||||
this.docfields = docfields;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -198,11 +193,6 @@ export default class GridRow {
|
|||
);
|
||||
}
|
||||
refresh() {
|
||||
// update docfields for new record
|
||||
if (this.frm && this.doc && this.doc.__islocal) {
|
||||
this.set_docfields(true);
|
||||
}
|
||||
|
||||
if (this.frm && this.doc) {
|
||||
this.doc = locals[this.doc.doctype][this.doc.name];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,8 +91,8 @@ $.extend(frappe.meta, {
|
|||
};
|
||||
},
|
||||
|
||||
get_docfields: function (doctype, name, filters) {
|
||||
var docfield_map = frappe.meta.get_docfield_copy(doctype, name);
|
||||
get_docfields: function (doctype, name, filters, docfield_list = null) {
|
||||
var docfield_map = frappe.meta.get_docfield_copy(doctype, name, docfield_list);
|
||||
|
||||
var docfields = frappe.meta.sort_docfields(docfield_map);
|
||||
|
||||
|
|
@ -125,11 +125,11 @@ $.extend(frappe.meta, {
|
|||
});
|
||||
},
|
||||
|
||||
get_docfield_copy: function (doctype, name) {
|
||||
get_docfield_copy: function (doctype, name, docfield_list = null) {
|
||||
if (!name) return frappe.meta.docfield_map[doctype];
|
||||
|
||||
if (!(frappe.meta.docfield_copy[doctype] && frappe.meta.docfield_copy[doctype][name])) {
|
||||
frappe.meta.make_docfield_copy_for(doctype, name);
|
||||
frappe.meta.make_docfield_copy_for(doctype, name, docfield_list);
|
||||
}
|
||||
|
||||
return frappe.meta.docfield_copy[doctype][name];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue