This method is daily scheduler_events which is calling from ERPNext hooks.py and placed in Email Campaign Doctype. I want to override it in custom app.
This method is not called by any class of doctype.I want to Override ERPNext scheduler events which is in hooks.py.
Ok but why you want to override it ? I’m asking you as I haven’t done this but if you have specific task or something where you need to customise, update, add something in that logic I’ll try and let you know.
I just want to Override ERPNext scheduler events. Let me know if you find something.
Why do you want to override? What is the actual problem you want to solve? Maybe there is another approach to solve the situation?
hello @moe01325
In Email Campaign , there is set_email_campaign_status method which runs daily as it is in schedular events. But this method has error as it is not updating status in database. And because of this issue Email Campaign is not working. So I want to override this method to solve this by saving updated status in database.
Earlier Email Campaign issue is discussed. But there was no solution.
So I have checked core methods and found error in this method which is responsible for this issue.
Call the path in hooks. And in that python import the core class.
In hooks,
ToDo:“customapp.overides.customToDo”
In python,
from erpnext.erpnext.module.doctype.doctype_py Import ToDo
class customToDo(ToDo):
def validate(self):
super().validate()
#your code
Here super is to run the core
This override Class method. I want to override core function which is also not whitelisted.
Try Monkey Patch!
If you really have to override, the practice is to do this :
- override the whole class which contains the code of that function or method
- inside the overrided code → put your custom code inside that function or method
by doing this the system will use your overrided class and your custom code inside the override file
Recently i found a solution:
Suppose we have a function send_mail in email_campaign.py
path: apps/erpnext/erpnext/crm/doctype/email_campaign/email_campaign.py
there is a method send_mail which is not whitelisted and not under any class
Override steps:
- Create a .py file in your custom app and do changes in send_mail function
- Goto __ init __.py file add paths like this
Can you please help me on same?
yes , you can do the same thing with other method which is not whitelisted or not under class.
yes , you can do the same thing with other method which is not whitelisted or not under class.
Thanks for sharing solution
But this monkey override will apply on the global
Erpnext for all sites not only the site where the custom app have the override
There is solution for it
can you please explain a bit more ??
you could check for the site within the custom app?
i mean this override apply on the global erpnext code for all sites
not only the site where override is made