ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

Item wise delivery date in Sales invoice table from delivery date of sales order item table


#1

I want to import delivery date from sales order items table to sales invoice order table.
I have created delivery date field in table of sales invoice.
that means when I am making sales invoice of any sales order by clicking on “make ----> invoice”
or "Sales Invoice -----> new----->get items from -----> sales order "
then it should fetch the delivery date of that particular items into the sales invoice table of items.

delivery date in sales order


want the date here in sales invoice

I have tried following script but its fetching some random dates in table without making sales order, as onload is used

frappe.ui.form.on("Sales Invoice", "onload", function(frm, cdt, cdn) {
frappe.call({
    method: "frappe.client.get_list",
    args: {
        doctype: "Sales Order",
            filters: {
              "name": frm.doc.sales_order,
    },
      
        fields: ["delivery_date"]
    },
    callback: function(r) {
        var items = [];
        frm.clear_table("items");
        for (var i = 0; i < r.message.length; i++) {
            var d = frm.add_child("items");
            for (var key in r.message[i]) {
                if (r.message[i].hasOwnProperty(key)) {
                    frappe.model.set_value(d.doctype, d.name, key, r.message[i][key]);
                }
            }

            if (!d.qty) d.qty = 1;
        }
        frm.refresh_field("items");
    }
   })
 })