ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

How to Override python function to customize erpnext or use in app


#1

Hi,how can i customize Dashboard section of Project without changing core erpnext.

This code is from project_dashboard.py
I need to customize Project Dashboard

 from __future__ import unicode_literals
 from frappe import _
 
 def get_data():
 	return {
 		'heatmap': True,
 		'heatmap_message': _('This is based on the Time Sheets created against this project'),
 		'fieldname': 'project',
 		'transactions': [
 			{
 				'label': _('Project'),
 				'items': ['Task', 'Timesheet', 'Expense Claim', 'Issue' , 'Project Update']
 			},
 			{
 				'label': _('Material'),
 				'items': ['Material Request', 'BOM', 'Stock Entry']
 			},
 			{
				'label': _('Sales'),
 				'items': ['Sales Order', 'Delivery Note', 'Sales Invoice']
 			},
 			{
 				'label': _('Purchase'),
 				'items': ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice']
 			},
 		]
 	}

How to Override python function to customize erpnext
#2

you can monkey patch that function as explained here : https://www.geeksforgeeks.org/monkey-patching-in-python-dynamic-behavior/

you would do this in hooks.py for your app, since that gets called early in the bootstrap process, the project function will then be overridden.


#3

Thanks @cjpit

For normal events like validate(),on_submit() function we are using hooks

can i have a sample program to manage this


#4

Any sample code to know about monkey patching.i wrote monkey patching code in hooks.py and it is working fine.what if more functions to changes

can we write monkey patching in other files than hooks.py