Validate document before insert

hello
I doing custom validation on some fields
I have used validate function on controller like that

def validate(self):
	if self.status == 'delivering' :
		if not self.deliveryman :
			msgprint(_("Please choose deliveryman "))
			
	frappe.db.set(self, 'start_dt', datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

but I do not need document to be saved on after check validation
how can i make frappe not to save document ?
thanks

try throw instead of msgprint

frappe.throw(__("Please choose deliveryman "));
1 Like