Dears
I`m planning to make delivery dates automatically for sales orders so the delivery date field will be read only for the user
what i did
1- i`v created a new int custom field in both item & Sales order item doctypes named ( delivery_days).
2- then fetched it successfully be the following custom script
cur_frm.add_fetch(“item_code”,“delivery_days”,“delivery_days”);
3- then i`m trying to get item delivery date = nowdate() + delivery_days by the following script
frappe.ui.form.on(‘Sales Order Item’, ‘delivery_days’, function(frm){
frm.set_value(“delivery_date”, frappe.datetime.add_days(frappe.datetime.nowdate(), frm.doc.delivery_days));
})
but if i replaced frm.doc.delivery_days with int like 10 or 12 it works fine like
frappe.ui.form.on(‘Sales Order Item’, ‘delivery_days’, function(frm){
frm.set_value(“delivery_date”, frappe.datetime.add_days(frappe.datetime.nowdate(), 12));
})
so whats wrong with my script ???
Hi
Correct code
frm.doc.delivery_days
change to
locals[cdt][cdn].delivery_days
cur_frm.add_fetch("item_code","delivery_days","delivery_days");
frappe.ui.form.on("Sales Order Item", "delivery_days", function(frm, cdt, cdn){
frm.set_value("delivery_date", frappe.datetime.add_days(frappe.datetime.nowdate(), locals[cdt][cdn].delivery_days));
})
Dears It works but
Sales order final delivery date takes the last item row delivery day
for ex:
if the sales order date 1-1-2018
and the 1st row delivery days 30 so its delivery date will be 31-1-2018 and also the sales order final delivery date takes that date
but if the 2nd row has only 2 delivery days then the final delivery date for the sales order will be 3-1-2018
and its wrong
what we need is to get the fairest delivery date for the all rows to be copied into final delivery day not the last row only
so what can i do ??
sorry for up for the 2nd time but does any one has idea about this issue ?
Can i use If condition in custom script like
frappe.ui.form.on("Sales Order Item", "delivery_days", function(frm, cdt, cdn){
if (frm.doc.from_date < ("delivery_date", frappe.datetime.add_days(frappe.datetime.nowdate(), locals[cdt][cdn].delivery_days) ) {
frm.set_value("delivery_date", frappe.datetime.add_days(frappe.datetime.nowdate(), locals[cdt][cdn].delivery_days));
}
})
umair
January 22, 2018, 9:35am
12
@rohit_w @vishdha can you please assist on this?
1 Like
its working well for item delivery date
but sales order delivery date takes the last item delivery date in items table
it should takes the fairest delivery date of the entire items table delivery date not the last row delivery date
what should i do and how can we merge it ??