I am doing some customisation in POS?
I want to add vehicle number and customer type in POS.
Now, I am stuck at erpnext python code overriding?
In some cases we can use hooks before insert, after insert to write own python code, but this is not possible for current case as data is coming from local storage.
Is it possible to override exiting python methods?
How to access local storage in python?
Why not start contributing fixes instead
@rmehta The complete feature will be enable bold fields in pos.
For this current fix, we just need to update below code. and loop data (data is local storage customer list here)
Please advise on it.
customer_doc = frappe.new_doc('Customer')
customer_doc.customer_name = data.get('full_name') or data.get('customer')
customer_doc.customer_pos_id = data.get('customer_pos_id')
customer_doc.customer_type = 'Company'
customer_doc.vehicle_no = data.get('vehicle_no')
customer_doc.customer_group = get_customer_group(data)
customer_doc.territory = get_territory(data)
customer_doc.flags.ignore_mandatory = True
customer_doc.save(ignore_permissions = True)
In custom_app module_name.py
from erpnext.accounts.doctype.sales_invoice.sales_invoice import SalesInvoice
SalesInvoice.shoutout = shoutout
SalesInvoice.before_cancel = before_cancel
In : from custom_app.module_name import build_my_thing
In : build_my_thing()
In : sales_invoice = frappe.get_doc("Sales Invoice", "SINV-00165")
In : sales_invoice.shoutout()
In : sales_invoice.cancel()
Thanks for the solution. I have marked this as solution as its working fine for overriding class method.
However this will not work in my case, as I need to override method which doesn’t belong to any class.
@revant_one I have been looking for such a method for a while. This is great pointer.
Quick Question - How is this loaded in the ERPNext context? Would you call build_my_thing() function on load of the core doctype? I’m no able to grasp when the bench would load the overridden function…
build_my_thing just before you need to do overridden action.
onload, before frappe.get_doc or frappe.new_doc.
also, just like classes same thing is possible with modules.
Try it in
Thanks @revant_one I tried using befoe_insert and onload. It works, but works inconsistently. Sometimes the custom method is called, but then other times, original method is called…doctype needs to be reloaded to call the custom method again…I dont know when it happens/ any thoughts?
This thread is really popular. So I am posting this here.
You can now override a standard DocType class via hooks:
Is this different to this existing hook?
@netchampfaris what about the method not belong to a class?
Like this file frappe/frappe/utils/data.py
Other form that you can use to override methods in an application is call
build_my_thing function at the end of
hooks.py file. Specially userful when the method is in a class controller. We are testing that solution but apparently it works.
how to override the python method (not a whitelisted method and also not a method inside the class) which is in the erpnext app @rmehta @netchampfaris @revant_one @Mohammed_Redha @peterg
Did you check below before tagging to so many people ? What you have done so far and what are you trying to do ?
@sanjay yes I tried, I can able to override the whitelisted erpnext method from custom app via hooks.py and also a method inside the class, but i could not able to override the python method
Were you able to achieve it? I’m using
override_doctype_class of hooks but it’s not working…
Hi @netchampfaris I need to use
override_doctype_class hook but not sure if I’m missing something because it’s not working for me. The method metioned in the
override_doctype_class is not reached. Could you please help?