yes ill try but cant get the result
is there any message in browser console?
I know the problem. the child in payment reference is added automatically. I will let you know later.
It will calculate different day and assign to no_of_days_fr_delivery before the form Payment Entry save. After form saved, you can see the diff date.
frappe.ui.form.on("Payment Entry", {
validate: function(frm) {
$.each(frm.doc.references || [], function(i, d) {
var diff_day = frappe.datetime.get_diff(d.due_date, frm.doc.posting_date);
frappe.model.set_value(d.doctype, d.name, "no_of_days_fr_delivery", diff_day);
});
}
});
if you want to see diff day before form Payment Entry save, you may consider to change the core.
c.no_of_days_fr_delivery = frappe.datetime.get_diff(d.due_date, cur_frm.doc.posting_date);
after you saved the Payment Entry, field No of Days fr delivery is still empty?
yes still empty.
can you use the code below and share the message in you browser console?
frappe.ui.form.on("Payment Entry", {
validate: function(frm) {
$.each(frm.doc.references || [], function(i, d) {
var diff_day = frappe.datetime.get_diff(d.due_date, frm.doc.posting_date);
console.log(diff_day, d);
});
}
});
The script was called. but wrong calculation as it return zero or post date == due_date. can you expend Object in console and check what is the due_date?
Child table doesn’t store due_date, so it always return zero. Please try code below.
frappe.ui.form.on("Payment Entry", {
validate: function(frm) {
$.each(frm.doc.references || [], function(i, d) {
frappe.db.get_value(d.reference_doctype,d.reference_name,"due_date", function(value){
var diff_day = frappe.datetime.get_diff(value["due_date"], frm.doc.posting_date);
frappe.model.set_value(d.doctype, d.name, "no_of_days_fr_delivery", diff_day);
});
});
}
});
When you’re at Payment Entry and Payment Entry Reference have items loaded.
can you run the code below in your browser console, and check whether No of Days fr Delivery have value.
I have tested it, it works.
$.each(cur_frm.doc.references || [], function(i, d) {
frappe.db.get_value(d.reference_doctype,d.reference_name,"due_date", function(value){
var diff_day = frappe.datetime.get_diff(value["due_date"], cur_frm.doc.posting_date);
frappe.model.set_value(d.doctype, d.name, "no_of_days_fr_delivery", diff_day);
});
});
posting date = “2018-02-08”
due_date = “2017-10-23”
diff_date = -108
I have assigned diff_day to allocated_amount as image below.
yes it works but theres a mild error here when ill try to make another it will not compute the result. but when i refresh and save again the answer will show.