Creating App is failing : confusion

Hi

ERPNext: v12.28.0 (version-12)
Frappe Framework: v12.25.0 (version-12)

I have been trying to get my teeth into some customization but I have always done it
within an existing modules. Which everyone will tell me that it is not the best to do, which I
learned the hard way by having to use the --reset switch when I updated my one server.

SO I did some reading and found some stuff…

https://frappeframework.com/docs/v13/user/en/tutorial/create-an-app
( of course replacing name where applicable)

the procedure is basically…

$ bench new-app library_management

Installing library_management
$ ./env/bin/pip install -q -U -e ./apps/library_management
$ bench build --app library_management
$ FRAPPE_ENV=production node rollup/build.js --app library_management

I followed this procedure and all went well until the last instruction …

FRAPPE_ENV=production node rollup/build.js --app john_module

which yielded this error …

internal/modules/cjs/loader.js:818
throw err;
^

Error: Cannot find module ‘/home/erpnextjohn/frappe-bench/rollup/build.js’
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
at Function.Module._load (internal/modules/cjs/loader.js:667:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47 {
code: ‘MODULE_NOT_FOUND’,
requireStack: []

I then found this discussion …

Observations…

  1. If I log onto the backend via SSH, I can see the new app under ./apps
  2. If I log onto the front-end ( desk) and go to
    /desk#List/Module%20Def/List

I can see my module
3. When I just enter my server URL, I can log onto my desk, but nowhere can I find my
Module

And with all this I realised my shortfall …
I don’t know what to expect. i.e. I don’t know where my module must “show up”

My goal…
Is to create a space where I can mess around with my own doctypes within ERPNext and not
loose any work when I update. But if I look at the folder structure ( via SSH ) then my App
(John Module) is rigth next to Erpnext at ./apps. This to me means, my app is totally
separate from ERPnext.

And in the one posting I saw the structure …

App -> Module -> Doctype

which makes sence, but where do I see them?

If someone can just help me out of the darkness so that I can have a space to play around
with doctypes in a “safe” way, please.

Hi John,

When it comes to Apps, there is a 2-step process:

  1. Create the App.

    • This is the command you mentioned ‘bench new-app library_management’.
    • When you run this command, Bench creates a subdirectory:

    ../apps/library_management

However… the App is not-yet-installed for your particular Frappe Site!

One way to think of this is “downloading a program…but not -installing- it.

  1. Install the App:
    • `bench --site <your_site_name> install-app library_management
    • This step makes some changes in MySQL. For example, it creates a new row in table 'tabModule Def' for every Module in your App.

How do you know what Apps are installed? The easiest way is to login via the browser, click on “Help” then “About”. You will see a list of all Installed Apps.

Regarding Modules

From a Linux file system perspective, here’s what you’ve got:

 apps
 ├── frappe
 └── library_management                     # This is the root of the App's git repository
         ├── library_management             # This is the top-level Python module for your App
                ├── config
                ├── library_management      # This is the first "Frappe Module" for your App
                ├── hooks.py
                ├── __init__.py
                ├── modules.txt
                ├── patches.txt 
                ├── public
                 ...

Note: There is a substantial difference between a Python “module” and a Frappe “Module”. Notice my use of capital letters in the example above.

To see what Frappe Modules you have? Use the awesomebar and search for “Module Def List”

Which should display a web page like this:

Finally, you can see the relationship between DocType and Module by just opening the DocType List page:

Hopefully this gets you back on track!

Thank you @brian_pond for your extensive answer !

I understand everyone is busy and for you to take the time to do all this is appreciated…

I did go ahead and did (2) … install the app.

And I can see the app in the all places that you highlight in your post.
I have also gone ahead and created a doctype in the module, which I can see in the list.

The one thing that I was expecting is to be able to access my module from the Desk?

Thanks @brian_pond

You are very welcome. Learning these things can be difficult. The things you’re doing today? They stumped me previously too. :slightly_smiling_face:

In version 12 and earlier, adding things to Desk is tricky. One way to see how it’s accomplished is by examining how the ERPNext App works (remembering that ERPNext is, itself, just a custom App)

Check out these files:

  1. ../apps/erpnext/erpnext/config/desktop.py

This ‘desktop.py’ file defines which Modules are shown on the Desk. You’ll want your own ‘desktop.py’, located in the same relative path to your App. Use the code from ERPNext’s ‘desktop.py’ as your template. Just change the code to reflect your own Module names and definitions.

  1. ../apps/erpnext/erpnext/config/selling.py

The Python module “selling.py” is the ERPNext Module “Selling”. It corresponds to the Selling menu on the Desk. These “Module files” are how define your Module’s appearance on Desk: links to DocTypes, Reports, and Pages.

There’s also a ‘buying.py’ for the Buying menu, a ‘stock.py’ for the Stock menu, and so on.

Use these existing files as templates to help get started. For each of your App’s Modules, you’ll make a similar file. Again, in a path to relative to your App’s directory. Each file defines how that Module displays on Desk.

Note 1: Sometimes you’ll make changes, but they won’t show up on your Desk. A common reason is that Frappe Framework (and Python) really, -really- love to cache values! Especially semi-static information, like Desk structure. After you’ve made your changes, you definitely want to click on “Settings” at the top of your browser window, then “Reload”. This will clear one of those caches.

Note 2: If that fails to make Desk display your icons (and sometimes it might), you may have to stop and restart the ERPNext web service.

Note 3: If -that- fails, then try deleting all Python bytecode (*.pyc) files in your bench directory, and its sub-directories.

Follow-up to my post above. If you’re on Version 13+, my post above is obsolete. Instead, you have Workspaces, which are configurable using the web browser alone.

Yes, the learning process for these things seem to have its hurdles, but I trust it will also get
me to a better understanding of how everything fits together … frappe … bench … apps

Yes, I have decided to stick to V12 for now so I shall look at your procedure.

Thanks again for the info. Let me work through this. It is important that I get my work
environment sorted because I would like to start contributing by making code suggestions
or even pull-requests, instead of just “asking” the whole time for features !

I would LOVE 2 features ( issues already raised)…

  1. “Generate Certificate” in Education. Already hacked the code and its working but I would like
    to get it to a stage where I can generate a pull-request.

  2. Barcode scanner usage with “Stock Reconciliation”. Also hacked the code and 99% working.

I shall revert with results !

1 Like

Hi

Happy to say I have my module on my desk.

Screenshot of desk…

And my first doc inside my module…

Once again, thank you @brian_pond for taking the time to help me with this.
Really appreciate it !

Now the pressure is on me to start writing code !! he-he !!

I think first thing … get my stock recon code in there …

i can already see the next challenge … its all very romantic to write code on this, my
test server, but I need to get it to my production server. But lets cross that bridge
when we get there. I dont want to digress in this thread.

I am going to mark the solution so others can pick it up as well and also to close the
thread .

1 Like

Additional …

For anyone reading this post that can now create their own module and you wonder where
your JS , JSON , PY files are when you create your new doctype …

Please refer to this post …