Robot
July 17, 2024, 9:37am
1
Hi Team,
I’m trying to override the InboundMail class to achieve some more functionalities, Could anyone ever do this, if so I’d like to get some idea on this.
We have customized the Task Doctype and added some fields where the employee is set to mandatory. So whenever I receive an email I want to create a Task and in the employee field I wanna assign someone from our account team. So for this, I would need to override the InboundMail Class.
Meet
July 17, 2024, 10:06am
2
@Robot Please Refer This Address Doctype Class Override is refrence for how to override your inboundmail class
email_css = "email_erpnext.bundle.css"
doctype_js = {
"Address": "public/js/address.js",
"Communication": "public/js/communication.js",
"Event": "public/js/event.js",
"Newsletter": "public/js/newsletter.js",
"Contact": "public/js/contact.js",
}
override_doctype_class = {"Address": "erpnext.accounts.custom.address.ERPNextAddress"}
override_whitelisted_methods = {"frappe.www.contact.send_message": "erpnext.templates.utils.send_message"}
welcome_email = "erpnext.setup.utils.welcome_email"
# setup wizard
setup_wizard_requires = "assets/erpnext/js/setup_wizard.js"
setup_wizard_stages = "erpnext.setup.setup_wizard.setup_wizard.get_setup_stages"
setup_wizard_complete = "erpnext.setup.setup_wizard.setup_wizard.setup_demo"
setup_wizard_test = "erpnext.setup.setup_wizard.test_setup_wizard.run_setup_wizard_test"
1 Like
Robot
July 17, 2024, 10:14am
3
Hi @Meet Thanks for your response.
I’ve tried this but it isn’t working, because Address is a doctype so we would override like this but InboundMail is just a class right?
That’s why it’s not working I guess.
There could be other to override this
Meet
July 17, 2024, 10:18am
4
@Robot Please Check This Document for write custom code to override class function
Monkey Patch to add method in SalesInvoice
Hello, I need to add a custom method in SalesInvoice DocType.
I’ve tried with no success to add a monkey patch in hooks.py of my custom app as follow:
#hooks.py
from erpnext.accounts.doctype.sales_invoice.sales_invoice import SalesInvoice
def my_method(self):
return 'Foo'
SalesInvoice.my_method = my_method
Any ideas?
Thanks!
1 Like
Robot
July 17, 2024, 10:47am
5
Yeah, I’ve tried Monkey Patch @Meet . It is working.
from frappe.email.receive import InboundMail
from ss_custom_erpnext.ss_custom_erpnext.email.receive import CustomInboundMail
InboundMail._create_reference_document = CustomInboundMail._create_reference_document
I’ve added like this in my custom app init file