Need help for calculating date in custom field

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:

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,, ‘custom_expected_arrival_date’, expected_arrival_date);

If the custom__shipping_time_in_days field is present in the Item master, I recommend you first retrieve the custom__shipping_time_in_days details into the Purchase Order item table and then calculate them. This approach is straightforward. However, if you need to fetch the custom__shipping_time_in_days directly from the Item master, you will need to use the method to obtain these details.