Try ERPNext Buy Support Partners Foundation

Custom script in Stock Entry for Price List

Is there a custom script i can use to display price list rate per item in Stock Entry? Thanks!

Hi @airzoink,

Add custom field price list on the stock entry details table and use below script

frappe.ui.form.on("Stock Entry Detail", {
	item_code: function(frm, cdt, cdn) {
		child 
		me.frm.call({
			method: "frappe.client.get_value",
			args: {
				doctype: "Item Price",
				fieldname: "price_list_rate",
				filters: { item_code: child.item_code, price_list : child.price_list},
			},
			callback: function(r, rt) {
				if(r.message) {
					frappe.mode.set_value(cdt, cdn, 'fieldname', r.message.price_list_rate)
				}
			}
		});
	}
})
1 Like

@rohit_w Thanks! Will i be able to specify which price list to use? Similar to Quotation and Sales Order?

Hi @airzoink ! You can create custom field link to your pricelist doctype. Then integrate it with your script to just pick up prices there. :slight_smile:

@creamdory I tried making Price List link but i do not know how to integrate it with the script above. Can you help me with this? :slight_smile:

Hi @airzoink,

Did you added custom field on stock entry detail doctype? If yes then just goto Custom script > select doctype as stock entry > paste above script under Script field > save it.

On stock entry, select the price list first and then item code, one more thing you have to set the name of the field instead of fieldname in which you want to set the rate

@rohit_w
What i have done:

  • Added “Price List Rate” data field type in Stock Entry Detail
  • Added “Selling Price List” link field type in Stock Entry
  • Added your code as a Custom Script under Stock Entry DocType and changing the ‘fieldname’ to ‘selling_price_list’

I must be doing something not right since i don’t see the changes.

Fieldtype should be of type currency not data

use below code

frappe.ui.form.on("Stock Entry Detail", {
	item_code: function(frm, cdt, cdn) {
		child 
		me.frm.call({
			method: "frappe.client.get_value",
			args: {
				doctype: "Item Price",
				fieldname: "price_list_rate",
				filters: { item_code: child.item_code, price_list : frm.doc.selling_price_list},
			},
			callback: function(r, rt) {
				if(r.message) {
					frappe.mode.set_value(cdt, cdn, 'price_list_rate', r.message.price_list_rate)
				}
			}
		});
	}
})

where,
fieldname is price_list_rate
price list is selling_price_list

Thanks

Made changes as you described. But price rate is still not displayed.

Hi @airzoink,

share browser’s console log

Browser’s Console Log

VM1511:509 Uncaught ReferenceError: child is not defined(…)item_code @ VM1511:509(anonymous function) @ form.min.js:254(anonymous function) @ form.min.js:254map @ jquery.min.js:2trigger @ form.min.js:254(anonymous function) @ form.min.js:33(anonymous function) @ desk.min.js:548each @ jquery.min.js:2run @ desk.min.js:548trigger @ desk.min.js:548set_value @ desk.min.js:547set_model_value @ desk.min.js:384set @ desk.min.js:383callback @ form.min.js:261callback @ desk.min.js:133200 @ desk.min.js:135(anonymous function) @ desk.min.js:140i @ jquery.min.js:2fireWith @ jquery.min.js:2z @ jquery.min.js:4(anonymous function) @ jquery.min.js:4

Hi @airzoink

oops got the issue

frappe.ui.form.on("Stock Entry Detail", {
	item_code: function(frm, cdt, cdn) {
		child = locals[cdt][cdn];
		me.frm.call({
			method: "frappe.client.get_value",
			args: {
				doctype: "Item Price",
				fieldname: "price_list_rate",
				filters: { item_code: child.item_code, price_list : frm.doc.selling_price_list},
			},
			callback: function(r, rt) {
				if(r.message) {
					frappe.mode.set_value(cdt, cdn, 'price_list_rate', r.message.price_list_rate)
				}
			}
		});
	}
})
1 Like

Applied. New error

VM2241:519 Uncaught TypeError: Cannot read property ‘set_value’ of undefined(…)callback @ VM2241:519opts.callback @ form.min.js:176callback @ desk.min.js:133200 @ desk.min.js:135(anonymous function) @ desk.min.js:140i @ jquery.min.js:2fireWith @ jquery.min.js:2z @ jquery.min.js:4(anonymous function) @ jquery.min.js:4

Hi @airzoink

frappe.model.set_value(cdt, cdn, 'price_list_rate', r.message.price_list_rate)

Success! :grinning:

@rohit_w
By the way can the script only show selling rates and not buying rate?

Hi @airzoink,

It shows the rate of the selected price list, so don’t select the buying price list or use get_query for price list to show only selling price list.

@rohit_w

Can you give me an example on how to apply get_query?

Thanks!

Hi @airzoink

check

@rohit_w

Based on the original script you have provided. Where do i insert these 7 lines of code?

If i edit it based on what i understand would it look like this?

frm.fields_dict.selling_price_list.get_query = function() {
return {
filters:{
‘selling’: ‘Yes’
}
}
}

Sorry i’m really a beginner at this. But i’m trying to understand bit by bit. :slight_smile: