recalculate terms when document date changed (#12288)
* recalculate terms when document date changed
* clean up
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 1814061..483736e 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -521,6 +521,7 @@
if(r.message) {
me.frm.set_value("due_date", r.message);
frappe.ui.form.trigger(me.frm.doc.doctype, "currency");
+ me.recalculate_terms();
}
}
})
@@ -530,6 +531,29 @@
}
},
+ recalculate_terms: function() {
+ const doc = this.frm.doc;
+
+ if (doc.payment_terms_template) {
+ this.payment_terms_template();
+ } else if (doc.payment_schedule) {
+ const me = this;
+
+ doc.payment_schedule.forEach(
+ function(term) {
+ if (term.payment_term) {
+ me.payment_term(doc, term.doctype, term.name);
+ } else {
+ frappe.model.set_value(
+ term.doctype, term.name, 'due_date',
+ doc.posting_date || doc.transaction_date
+ );
+ }
+ }
+ );
+ }
+ },
+
get_company_currency: function() {
return erpnext.get_currency(this.frm.doc.company);
},