Hello,
I like to add to each purchase order item an information for the arrival (custom_expected_arrival_date) at our warehouse. This is based on the confirmed delivery date (expected_delivery_date) from the supplier and the needed shipping time (custom_shipping_time_in_days) in days saved in the items table.
I have tried to different client scripts already:
1.
cur_frm.cscript.custom_expected_arrival_date = function(doc, cdt, cd){
cur_frm.set_value(“custom_expected_arrival_date”, frappe.datetime.add_days(doc.expected_delivery_date, flt(doc.item.custom_shipping_time_in_days)));
}
frappe.ui.form.on(‘Purchase Order’, {
validate: function(frm) {
// Iterate through each item
frm.doc.items.forEach(function(item) {
// Get the exworks date for each item
var exworks_date = item.expected_delivery_date;
// Get the shipping time for each item
var shipping_time = frappe.db.get_value(“Item”, item.item_code, “custom__shipping_time_in_days”);
// Calculate expected arrival date for each item by adding shipping time to exworks date
var expected_arrival_date = frappe.datetime.add_days(exworks_date, flt(shipping_time));
// Set the calculated value in the item’s custom_expected_arrival_date field
frappe.model.set_value(item.doctype, item.name, ‘custom_expected_arrival_date’, expected_arrival_date);
});
}
});