Functions after @frappe.whitelist()

I am unable to execute functions after @frappe.whitelist(). Can someone provide me a solution.

Can you share a code?

class OrderDetails(Document):
	def validate(self):

		# Remove duplicates
		found = {}
		i=-1
		k=5
		for selected in self.adding:
			i=i+1
			if selected.selected in found:
				#frappe.throw(_("Duplicate {0}").format(i))
				self.adding[found[selected.selected]].quantity = self.adding[found[selected.selected]].quantity + self.adding[i].quantity
				print "printgggggggggg"  #can you suggest me where I can see this print result?
				self.adding[i].quantity = 0
				self.adding[i].selected = 'product-04'
				
			if selected.selected not in found:
				found[selected.selected] = i




@frappe.whitelist()
def edit_table():
	db = MySQLdb.connect("restaurant.dev","root","root","1d2a8e9372" )
	cursor = db.cursor()
	query ="""DELETE FROM `tabAdd to Order` WHERE selected = 'product-04'; """
	cursor.execute(query)
        cursor.close()
	db.close()

Suggetion,

Frappe provides Database connection no need to create new connect. Use frappe.db.sql(yout_query)

which js method calling edit_table?

Can we only call a js method after @frappe.whitelist()?
If so I am sorry my question is wrong.

@ZodEnIX

Decorator for whitelisting a function and making it accessible via HTTP.
Standard request will be `/api/method/[path.to.method]`

:param allow_guest: Allow non logged-in user to access this method.

Use as:

@frappe.whitelist()
def myfunc(param1, param2):
	pass

Basically, whitelist method checks permissions, when any request requires to access python method.

So when you make REST call or want to access method from js you need to make those methods as whitelisted.

If you are calling a method from python no need to make it as whitelisted.

2 Likes