Override default validation

Hi guys,

Im trying to override the default validation at Expense Claim Type.

What im trying to achieve is to allow same company to be entered more than once.

This is default validation/

What i have done so far.

I create a .py with the same validation function as original expense claim type in my custom apps then at hook, i add validate under doc_event .

Im not sure if this a right method but im still not manage to override the validation yet hence im i need some help.

Thanks .

@ManasSolanki can you help?

Thanks for reply…im so glad if someone can help.

I think it is not possible right now.

This needs some more testing, but I was able to override validation (or any other function relevant at validation time) by introducing a new hook called “before_validate” to document.py.

## Two new lines added to document.py in run_before_save_methods
	def run_before_save_methods(self):
		"""Run standard methods before  `INSERT` or `UPDATE`. Standard Methods are:

		- `validate`, `before_save` for **Save**.
		- `validate`, `before_submit` for **Submit**.
		- `before_cancel` for **Cancel**
		- `before_update_after_submit` for **Update after Submit**

		Will also update title_field if set"""


		if self.flags.ignore_validate:

		if self._action=="save":
			self.run_method("before_validate") # new line
		elif self._action=="submit":
			self.run_method("before_validate") # new line
		elif self._action=="cancel":
		elif self._action=="update_after_submit":


Then, I added the hook to my app’s hooks.py:

doc_events = {
	"Relevant Doctype": {

Then, at the path listed above, I have the following function:

def override_validation(doc,method):
	RelevantDoctype.original_function = custom_function

I can get this posted as a pull request, but since it’s a relatively low-level function I thought it would be better to post it here first. Is there anything I am neglecting in this approach? It seems to work fine with no obvious performance implications.


can you please explain how can I override validate doc_event which is written in standard hooks.py file