ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

Best approach to edit ERPNext python doctypes


#1

I want to modify some python code in Price List . What is the best approach to do this?
I know I can modify directly the code, but in case I will upgrade to a later version the git pull will give me conflicts.
Do you have any idea?


#2

You can contribute ur use case as a PR


#3

I’m sorry, I did not understand you.


#4

@coldfire Try to Extend your customization in custom app


#5

An example?


#6

@coldfire What are you trying to do?


#7

There is a function def validate on erpnext/stock/doctype/price_list/price_list.py I want to modify the code on validate function. But, I do not want to do it directly on that file since it will modify source code and it will give me problem when I upgrade.


#8

@coldfire First go throw this:

https://frappe.io/docs/user/en/tutorial

then set your custom validate method in hook.py:
doc_events = {
“Price List”: {
“validate”: “custom_app.custom_app.doctype.custom_doctype.validate_list” #path of validate method
}
}


#9

It does not work.
I created a python fundtion:

def validate(self):
    if not cint(self.buying) and not cint(self.selling):
        throw(_("TEST"))

I tested the function if my path was correct with bench execute

I added in doc_events:

doc_events = {
    "Price List": {
        "validate": "energychoice_store.energy_choice_store.overriden_methods.price_list.validate"
    }
}

I executed these commands:
bench clear-website-cache && bench restart && bench build && bench migrate

And still does not override the function.


#10

You gave me a good idea but the thing is that it could not override.
So I modified a little bit by following these instructions:

Thank you for the help.