Fetching item prices in Opportunity

Hi @Leviatanus,

First, create a custom field like Price List in Opportunity DocType.

Then apply the client script.

frappe.ui.form.on('Opportunity Item', {
    item_code: function(frm, cdt, cdn) {
        var item = frappe.get_doc(cdt, cdn);
        var price_list = frm.doc.price_list; // Get the selected price list from the Opportunity DocType
        var item_code = item.item_code;

        frappe.call({
            method: 'frappe.client.get_value',
            args: {
                doctype: 'Item Price',
                filters: {
                    item_code: item_code,
                    price_list: price_list
                },
                fieldname: 'price_list_rate'
            },
            callback: function(response) {
                if (response && response.message) {
                    frappe.model.set_value(cdt, cdn, 'rate', response.message.price_list_rate);
                }
            }
        });
    }
});

Only worked if the Item will have a one-price list rate.

Item Price:

Output:

First, select the Price List, then after, select the Item code.
Item Rate will appear.

I hope this helps.
Thank You!

1 Like