Problem with fetching all details in child table

In quotation doctype I have item groups in which there are other items. I have fetched the all items of that perticular item group.but while fetching all the details I’m unable to fetch “rate” & “amount” column in table,where in last total of all items is calculated.

but In currency and price list when I re-selects the price list as “standard rate” then it shows all details correctly as shown in 2nd screenshot please suggest the changes in script


here is current script

frappe.ui.form.on("Quotation", "item_group", function (frm, cdt, cdn) {
    if(frm.doc.__islocal) {
        frappe.call({
            method: "frappe.client.get_list",
            args: {
                doctype: "Item",
                filters: {
                    "item_group": frm.doc.item_group,
                    "is_sales_item": 1
                },
                fields:["item_code", "item_name", "description", "stock_uom"]
            },
            callback: function(r) {
                    var items = [];
                    frm.clear_table("items");
                    for(var i=0; i< r.message.length; i++) {
                        var d = frm.add_child("items");
                        $.extend(d, r.message[i]);
                        if(!d.qty) d.qty = 1;
                        if(!d.uom) d.uom = d.stock_uom;
                    }
                    frm.refresh_field("items");
                }
        })
    }
});;

please suggest changes @schilgod

Hello,

Since you used a custom script to “override” the built-in behavior, you should also add a script to fetch the items’ rate and compute the amount for each row. :slight_smile:

@littlehera,thanks.for suggestion

I have already used the script for fetching items of the table.
when I’m selecting the price list again after fetching items as "standard rate"as shown in second screenshot it works as expected.
so now I want script to re-select/refresh the price list as “standard rate” after fetching the items so that i can get the all values and total as well.
if you have such script so that I will get my desired results,please share

Hmm… You can try adding frm.set_value('price_list', 'Standard Selling'); inside the callback function after the frm.refresh_field("items") code.

callback: function(r) {
                    var items = [];
                    frm.clear_table("items");
                    for(var i=0; i< r.message.length; i++) {
			//...
                    }
                    frm.refresh_field("items");
		    frm.set_value('price_list', 'Standard Selling');
                }

This should work.

frappe.ui.form.on("Quotation", "item_group", function (frm, cdt, cdn) {
if(frm.doc.__islocal) {
    frappe.call({
        method: "frappe.client.get_list",
        args: {
            doctype: "Item",
            filters: {
                "item_group": frm.doc.item_group,
                "is_sales_item": 1
            },
            fields:["item_code", "item_name", "description", "stock_uom"]
        },
        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");
            }
    })
}
});
2 Likes

its generating error “price_list” not found

@schilgod
thanks a lot…its working :blush:

1 Like

Great :+1:

1 Like