How to create document without user permission in codes?

I want to log some operations by hooking before_save and I do not want to give user create permission.

def create_item_price_log(doc, method=None, *args, **kwargs):
	from dmallerp import op_time

		origin_item_price = frappe.get_doc("Item Price",
		origin_item_price = type('', (object,), {})()
		origin_item_price.price_list_rate = -1

	now =
	doctype = doc.doctype

	log = frappe.new_doc("Item Price Log") = "{item_code}: {before}->{after}".format(item_code=doc.item_code, before=origin_item_price.price_list_rate, after=doc.price_list_rate)
	log.operator = frappe.session.user
	log.price_list = doc.price_list
	log.item = doc.item_code
	log.price_before = origin_item_price.price_list_rate
	log.price_after = doc.price_list_rate
	log.time = now

here is my code, but if I dont give user create permission, this will fail.

ok use hit my require.

1 Like