Custom app creation for doing customizations

Hi,

My basic requirement is to do customizations on the existing ERPNext and move them over to the AWS. I understand that I should create a custom app and also create an api.py file over there, which will override the existing methods. What I am confused about is the exact procedure. These are the steps that I followed.

  1. I created the git repository.

  2. Then, I created a custom app where I could maintain all
    the changes that I was going to make to the ERPNExt code. So, for
    example, I wanted the excise amount to be displayed in words, I followed
    these following methods:

    bench new-app custom.
    bench install-app custom

  3. After this, I opened the hooks.py file inside the custom app and added
    the code for calling the method from api.py file. This again I created
    inside the custom app. I am not sure whether I have to make changes to
    the hooks.py file inside the custom app or to the hooks.py file inside the erpnext app. Can you please help me here?

I might sound like a complete novice but these are some things which are actually giving me issues. Is there any step by step documentation for people like me who
have to do a lot of customizations on client’s sides.

@UmaG can you share your custom app?

You should add the doc_events in your custom app’s hooks file.

And for client side api, check documentation and existing code in erpnext.

Documentation: http://frappe.github.io/frappe/user/en/

Hi,

After creating the custom app, when I am trying to open the customize form or custom field on my ERPNext, I am getting this error:

Traceback (most recent call last):
File “/home/umag/frappe-bench/apps/frappe/frappe/app.py”, line 55, in application
response = frappe.handler.handle()
File “/home/umag/frappe-bench/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/umag/frappe-bench/apps/frappe/frappe/handler.py”, line 36, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/umag/frappe-bench/apps/frappe/frappe/init.py”, line 876, in call
return fn(*args, **newargs)
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/load.py”, line 68, in getdoctype
docs = get_meta_bundle(doctype)
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/load.py”, line 79, in get_meta_bundle
bundle = [frappe.desk.form.meta.get_meta(doctype)]
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/meta.py”, line 20, in get_meta
meta = frappe.cache().hget(“form_meta”, doctype, lambda: FormMeta(doctype))
File “/home/umag/frappe-bench/apps/frappe/frappe/utils/redis_wrapper.py”, line 149, in hget
value = generator()
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/meta.py”, line 20, in
meta = frappe.cache().hget(“form_meta”, doctype, lambda: FormMeta(doctype))
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/meta.py”, line 32, in init
self.load_assets()
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/meta.py”, line 39, in load_assets
self.add_code()
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/meta.py”, line 77, in add_code
self.add_html_templates(path)
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/meta.py”, line 88, in add_html_templates
for fname in os.listdir(path):
OSError: [Errno 2] No such file or directory: ‘/home/umag/frappe-bench/apps/custom/custom/custom/doctype/custom_field’

Thanks Nabin and Rushab,. I am getting this following error while I am
trying to open customize form or custom filed inside ERPNEXT.

Traceback (most recent call last):

File “/home/umag/frappe-bench/apps/frappe/frappe/app.py”, line 55, in
application
response = frappe.handler.handle()
File “/home/umag/frappe-bench/apps/frappe/frappe/handler.py”, line 19, in
handle
execute_cmd(cmd)
File “/home/umag/frappe-bench/apps/frappe/frappe/handler.py”, line 36, in
execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/umag/frappe-bench/apps/frappe/frappe/init.py”, line 876, in
call
return fn(*args, **newargs)
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/load.py”, line
68, in getdoctype
docs = get_meta_bundle(doctype)
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/load.py”, line
79, in get_meta_bundle
bundle = [frappe.desk.form.meta.get_meta(doctype)]
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/meta.py”, line
20, in get_meta
meta = frappe.cache().hget(“form_meta”, doctype, lambda: FormMeta(doctype))
File “/home/umag/frappe-bench/apps/frappe/frappe/utils/redis_wrapper.py”,
line 149, in hget
value = generator()
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/meta.py”, line
20, in
meta = frappe.cache().hget(“form_meta”, doctype, lambda: FormMeta(doctype))
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/meta.py”, line
32, in init
self.load_assets()
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/meta.py”, line
39, in load_assets
self.add_code()
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/meta.py”, line
77, in add_code
self.add_html_templates(path)
File “/home/umag/frappe-bench/apps/frappe/frappe/desk/form/meta.py”, line
88, in add_html_templates
for fname in os.listdir(path):
OSError: [Errno 2] No such file or directory:
‘/home/umag/frappe-bench/apps/custom/custom/custom/doctype/custom_field’

Reply as linked Topic

What path have you entered in doc_events in hooks?

Hi Nabin,

As I was facing issues yesterday, I reinstalled ERPNext and again created the custom app. So, there is nothing that I have added on the hooks.py file so far.

Thanks
Uma

I copied the doctype folder from frappe/custom to frappe-bench/apps/custom/custom and it seems to work. Not sure if this is the right way or not.

Hi,

I have tried to create the following code in the hooks.py file
doc_events = {
“Sales Invoice”: {
“on_update”: “custom.custom.api.set_total_in_words”

}

}

And, in my api.py file, which is present inside frappe-bench/apps/custom/custom/custom, i have added this following code:

@frappe.whitelist()
def set_total_in_words(doc, method):
print(“am i inside”)
from frappe.utils import money_in_words
company_currency = get_company_currency(doc.company)

    disable_rounded_total = cint(frappe.db.get_value("Global Defaults", None, "disable_rounded_total"))

    if doc.meta.get_field("base_in_words"):
        doc.base_in_words = money_in_words(disable_rounded_total and
            abs(doc.base_grand_total) or abs(doc.base_rounded_total), company_currency)
    if doc.meta.get_field("in_words"):
        doc.in_words = money_in_words(disable_rounded_total and
            abs(doc.grand_total) or abs(doc.rounded_total), doc.currency)
    if doc.meta.get_field("amount_of_duty_in_words"):
        doc.amount_of_duty_in_words = money_in_words(disable_rounded_total and
            abs(doc.excise_amount) or abs(doc.excise_amount), doc.currency)

My code is not getting executed. Is there anything that I am doing wrong here?

@UmaG can you share your app on GitHub so we can see what you are doing?

Hi @rmehta,

My app is at https://github.com/umaepoch/custom.

Thanks
Uma

I was not sure if I had done an install-app inside my site, so I ran

bench --site site1.local install-app custom

and I am getting this error:

File “/home/umag/frappe-bench/apps/frappe/frappe/database.py”, line 137, in sql
self._cursor.execute(query, values)
File “/home/umag/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/cursors.py”, line 205, in execute
self.errorhandler(self, exc, value)
File “/home/umag/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/connections.py”, line 36, in defaulterrorhandler
raise errorclass, errorvalue
frappe.exceptions.DuplicateEntryError: (u’Module Def’, u’Custom’, IntegrityError(1062, “Duplicate entry ‘Custom’ for key ‘PRIMARY’”))

In this: https://github.com/umaepoch/custom/blob/master/custom/hooks.py#L75

Should be custom.custom.api, or bring your api.py one folder up.

Also make sure you name your apps more creatively :slight_smile:

Hi @rmehta hope you are doing good. I am new to ERPNext and frappe. I have experience in python, ODOO and django.
I am trying to build a connector between erpnext and quickbooks that will sync customers between them. I could not find appropriate way to start. Can you please guid me how can I achieve that.

There is already a connector

Refer :

Thanks @revant_one. it is build using OAuth1 quickbooks is using OAuth2 since July, 2017. Is there any latest version of this connector or I will have to do changes

Hi @nauman_sharif, did you face any challenge connecting ERPNext to QuickBooks?
QuickBook has support for oAuth 2 now but support for version 1 is not yet deprecated and connector works well.

We are upgrading the app for ERPNext version 10 and will release updates once testing is complete.

1 Like

Hi @gupteshwar when connector with oAtuh2 support will release.
Yes I am facing challenges as I described in this link in reply to your response