From 87c21a89fe4bf3261d3a9a7d0a7d9eeefa7ea3d8 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:39:14 +0200 Subject: [PATCH 1/5] refactor: use `doc` parameter instead of `this.frm.doc` --- erpnext/public/js/controllers/transaction.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index becc6c18725..99731f20359 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1042,32 +1042,32 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe } } - due_date() { + due_date(doc) { // due_date is to be changed, payment terms template and/or payment schedule must // be removed as due_date is automatically changed based on payment terms // if there is only one row in payment schedule child table, set its due date as the due date - if (this.frm.doc.payment_schedule.length == 1){ - this.frm.doc.payment_schedule[0].due_date = this.frm.doc.due_date; + if (doc.payment_schedule.length == 1){ + doc.payment_schedule[0].due_date = doc.due_date; this.frm.refresh_field("payment_schedule"); return } if ( - this.frm.doc.due_date && + doc.due_date && !this.frm.updating_party_details && - !this.frm.doc.is_pos && + !doc.is_pos && ( - this.frm.doc.payment_terms_template || - this.frm.doc.payment_schedule?.length + doc.payment_terms_template || + doc.payment_schedule?.length ) ) { const to_clear = []; - if (this.frm.doc.payment_terms_template) { + if (doc.payment_terms_template) { to_clear.push("Payment Terms Template"); } - if (this.frm.doc.payment_schedule?.length) { + if (doc.payment_schedule?.length) { to_clear.push("Payment Schedule Table"); } From c55c77f4e9c48bbebe36cfc29ffbebde2b5bbaaa Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:40:50 +0200 Subject: [PATCH 2/5] fix: recognize trigger from child table --- erpnext/public/js/controllers/transaction.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 99731f20359..4b088c8054f 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1042,9 +1042,14 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe } } - due_date(doc) { + due_date(doc, cdt) { // due_date is to be changed, payment terms template and/or payment schedule must // be removed as due_date is automatically changed based on payment terms + if (doc.doctype !== cdt) { + // triggered by change to the due_date field in payment schedule child table + // do nothing to avoid infinite clearing loop + return; + } // if there is only one row in payment schedule child table, set its due date as the due date if (doc.payment_schedule.length == 1){ From 8a4db6958127a5c8c8d0c755c0e8e64bdf6321ab Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:53:04 +0200 Subject: [PATCH 3/5] fix: use the actual field label --- erpnext/public/js/controllers/transaction.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 4b088c8054f..80c92fabe3e 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1069,11 +1069,11 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe ) { const to_clear = []; if (doc.payment_terms_template) { - to_clear.push("Payment Terms Template"); + to_clear.push(__(frappe.meta.get_label(cdt, "payment_terms_template"))); } if (doc.payment_schedule?.length) { - to_clear.push("Payment Schedule Table"); + to_clear.push(__(frappe.meta.get_label(cdt, "payment_schedule"))); } frappe.confirm( From 57be8a85d6ebbf9e71b5f1f6389891d2b887f6c0 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:53:29 +0200 Subject: [PATCH 4/5] fix: clarify confirmation message --- erpnext/public/js/controllers/transaction.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 80c92fabe3e..0db09b775e0 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1078,8 +1078,11 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe frappe.confirm( __( - "Do you want to clear the selected {0}?", - [frappe.utils.comma_and(to_clear.map(dt => __(dt)))] + "For the new {0} to take effect, would you like to clear the current {1}?", + [ + __(frappe.meta.get_label(cdt, "due_date")), + frappe.utils.comma_and(to_clear) + ], ), () => { this.frm.set_value("payment_terms_template", ""); From c00f62d54a099b75d9b65ab548c51b5856ae7f9f Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:54:52 +0200 Subject: [PATCH 5/5] chore: add context --- erpnext/public/js/controllers/transaction.js | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 0db09b775e0..f7a5babd4e2 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1083,6 +1083,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe __(frappe.meta.get_label(cdt, "due_date")), frappe.utils.comma_and(to_clear) ], + "Clear payment terms template and/or payment schedule when due date is changed" ), () => { this.frm.set_value("payment_terms_template", "");