Hello,
i wan’t to fetch sales price from price list in custom field in purchase invoice. I didn’t find any example how to do that. I try to put value Price List Name from sales price doctype but it give me error
Hello,
i wan’t to fetch sales price from price list in custom field in purchase invoice. I didn’t find any example how to do that. I try to put value Price List Name from sales price doctype but it give me error
We did this using a custom function written in app.
PY Function.
from erpnext.utilities.product import get_price
@frappe.whitelist()
def get_spare_price(item_code, price_list, customer_group, company):
price = get_price(item_code, price_list, customer_group, company)
return price
JS Code to call the function and set price.
frappe.ui.form.on("Quotation Optional Accessories", "accessory", function(frm, cdt, cdn) {
var m = locals[cdt][cdn];
if(m.accessory){
frappe.call({
method: "app_folder.api.get_spare_price",
args: {
item_code: m.accessory,
price_list: frm.doc.selling_price_list,
customer_group: frm.doc.customer_group,
company: frm.doc.company
},
callback: function(r) {
rate = r.message["formatted_price"].split(" ")
price = (rate[1].replace(',', ''))
frappe.model.set_value(m.doctype, m.name, 'rate', price);
frappe.model.set_value(m.doctype, m.name, 'price_list_rate', price);
}
});
frm.add_fetch("stock_uom", "uom_name", "stock_uom");
}
});