How to set standard selling price to an item through python?

This is my code. But it is not setting standard selling price. I have given a default item group:

      def on_submit(doc, event):
    	for prem in range(len(doc.policy_premium)):
    		plans = [doc.policy_premium[prem].plan_1, doc.policy_premium[prem].plan_2, doc.policy_premium[prem].plan_3, doc.policy_premium[prem].plan_4]
    		for index in range(4):
    			frappe.db.sql("""
    					INSERT INTO `tabItem` (name, item_name, item_code, standard_rate)
    					VALUES
    						(%(name)s, %(item_name)s, %(item_code)s, %(standard_rate)s);
    				""",
    				dict(
    					name = f"{doc.name} - {doc.policy_premium[prem].maximum_trip_duration} Days - Plan {index+1}",
    					item_name = f"{doc.name} - {doc.policy_premium[prem].maximum_trip_duration} Days - Plan {index+1}",
    					item_code = f"{doc.name} - {doc.policy_premium[prem].maximum_trip_duration} Days - Plan {index+1}",
    					standard_rate = plans[index]
    				)
    			)

I believe the standard_rate field for Item doctype is just used to added the standard price when the item is created through hooks. If you’re adding the item directly to the database this hook won’t get executed.

If you want to set the standard rate after the item is created you should set it in the Item Price doctype.

@dj12djdjs is correct. Selling prices are stored in the DocType named ā€œItem Priceā€.

There is no ā€œstandardā€ Selling Price for an Item. Instead, you create 1 (or more) records in ā€œItem Priceā€. When you create documents like Sales Order lines, ERPNext will choose the Selling Price based on values in ā€œItem Priceā€ such as Item Code, Price List, Unit of Measure, Customer, Date Range, etc.

https://docs.erpnext.com/docs/v13/user/manual/en/stock/item-price

Than how to access Item Price and Link that to Item through Python?

Go to Item Price doctype and the structure you will see is pretty simple.

Here’s a quick bit of Python to create a new 'Item Price' for these conditions:

  • Item’s name = ā€˜Foo’
  • Unit of Measure = ā€˜Each’
  • Selling price = 1.23
new_price = frappe.new_doc("Item Price")
new_price.item_code = 'Foo'
new_price.uom = 'Each'
new_price.selling = True
new_price.price_list = 'Standard Selling'
new_price.price_list_rate = 1.23
new_price.save()
frappe.db.commit()
2 Likes

Thanks a lot…