From 2718685368f89cbc62c0d56a53806e1f613fd53c Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Sun, 20 Mar 2022 17:37:42 +0100 Subject: [PATCH] refactor: update_in_all_rows --- frappe/public/js/frappe/form/form.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/frappe/public/js/frappe/form/form.js b/frappe/public/js/frappe/form/form.js index 2e33e5c8ac..2c7a1e3543 100644 --- a/frappe/public/js/frappe/form/form.js +++ b/frappe/public/js/frappe/form/form.js @@ -1701,13 +1701,17 @@ frappe.ui.form.Form = class FrappeForm { } update_in_all_rows(table_fieldname, fieldname, value) { - // update the child value in all tables where it is missing - if(!value) return; - var cl = this.doc[table_fieldname] || []; - for(var i = 0; i < cl.length; i++){ - if(!cl[i][fieldname]) cl[i][fieldname] = value; - } - this.refresh_field("items"); + // Update the `value` of the field named `fieldname` in all rows of the + // child table named `table_fieldname`. + // Do not overwrite existing values. + if (!value) return; + + frappe.model + .get_children(this.doc, table_fieldname) + .filter(child => !child[fieldname]) + .forEach(child => + frappe.model.set_value(child.doctype, child.name, fieldname, value) + ); } get_sum(table_fieldname, fieldname) {