This lesson is part of the complete Frappe Framework and ERPNext developer training series. In this one, we will explore how to create a custom app in Frappe Framework and install it on our running instance.
When you are customizing an ERPNext instance, or you are building your own custom application using the Frappe Framework, there are some things you will find already done. Most of the time, these do not necessarily satisfy all our requirements. We may need to do a few changes here and there to suit our specific case.
Best practices dictate that we are not supposed to touch code written by Frappe or ERPNext teams. This is for the simple reason that in case they have an update, you will not be able to update your system, as your customization will be lost.
If you need to alter methods written by these teams, you will need to override the method with your own custom method. This is done by introducing the override to the hooks file inside your custom application, and then pointing the hook to the place where the class containing your custom method is.
from erpnext.education.doctype.student.student import Student
class KARANIStudent(Student):
def validate(self):
print("\n\n\n Student Values are being validated! \n\n\n")
Hooks File Code
override_doctype_class = {
"Student": "gch_custom.overrides.todo.KARANIStudent",
}
Auto-populating a child table in Frappe and/or ERPNext can make your application look good and give your users a better experience with the software. In this piece, I will demonstrate the following:
On this post I will provide the two pieces of code needed to finish the work:
We will to use a Custom Script to send the request to our custom endpoint and also to handle the response.
frappe.ui.form.on('Library Member', {
author: function(frm){
let author = frm.doc.author;
if(author){
frappe.call({
method: "library_management.api.get_author_articles",
args: {author: author}
}).done((r) => {
frm.doc.my_article = []
$.each(r.message, function(_i, e){
let entry = frm.add_child("my_article");
entry.article_name = e.name;
})
refresh_field("my_article")
})
}
}
})
We will write our Custom API endpoint which will be responsible for querying the data we need to return to the frontend.
@frappe.whitelist()
def get_author_articles(author):
articles = frappe.db.sql(f""" SELECT name FROM `tabArticle Library` WHERE article_author='{author}' """, as_dict=True)
return articles
Here is a YouTube video for the whole process.
When you install ERPNext for the first time, it sometimes gets frustrating when the fields are not properly arranged as you would expect. I will share some of the commands I have found useful in this article.
bench build – This command has more abilities if you supply additional options, but we just run it as this to build our app assets.
bench migrate – This command also has greater capabilities, but we are interested in only this basic one. It will run patches, sync schema and rebuild files/translations.
The bench migrate command may sometimes require you to supply the site name, especially when your instance is on production mode. In this case, just run:
bench –site [xyz] migrate
The last command I would like to share today, which clears your browser cache just in case you have cached content that may be causing this problem:
bench clear-website-cache
Here is a sample of the issue we are discussing here:
If you have other ways to solve this problem, please share in the comments section below.
When ERPNext is installed in development mode, you will have to restart the instance with the bench start command every time you want to access it. You can however start your instance when the server boots by setting up your instance for production.
In this article, I will show you a simple way to move your instance from development mode to production mode.
We will be using Supervisor to manage to manage the ERPNext process and Nginx as a reverse proxy to access the ERPNext process without using port 8000.
There are two ways this can be done. I will start with the simple and straightforward one.
Run the below commands from your bench directory:
sudo bench setup production [BENCH USER]
sudo supervisorctl restart all
If you are successful, your instance should be in production mode.
If this didn’t work for you, follow the following steps:
First, change the user to your bench user and install Supervisor and Nginx with the following command:
su - erpnext sudo apt-get -y install supervisor nginx
Next, install the frappe-bench add-on with the following command:
sudo pip3 install frappe-bench
Next, run the following command to configure ERPNext for a production environment:
sudo /home/erpnext/.local/bin/bench setup production erpnext
You should see the following output:
Site erpnext.example.com assigned port: 80 $ sudo /usr/bin/supervisorctl reread erpnext-redis: available erpnext-web: available erpnext-workers: available $ sudo /usr/bin/supervisorctl update erpnext-redis: added process group erpnext-web: added process group erpnext-workers: added process group nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful $ sudo systemctl reload nginx
At this point, ERPNext is installed and configured to run on port 80. Now, open your web browser and type in Your URL without the port.
When you install ERPNext for the first time, you may realize that you are running the developer version of both Frappe and ERPNext. You cannot proceed with the developer branch, as things keep changing, some of which may not be tested thoroughly.
In this video, you will learn how to switch from developer branch to the official release of both apps. I will also show you how to resolve all the issues that arise when you do the movement.
To switch from Developer to Official Branch, we run the command:
bench switch-to-branch version-13 frappe erpnext
After this has completed executing, the instance will prompt you to run the following command:
bench update –patch
When you run this command, most of the time you will get an error message that says:
No module names bleach_whitelist
When this happens, all you need to do is install this module in your environment. Note, I said environment. If you just run the command without specifying that you are installing it on the environment, it will not work. Frappe runs on an environment, and therefore all dependencies need to be installed on the environment.
Make sure that you are on the root directory of your instance, where you can see the env directory. Run the following command:
./env/bin/pip3 install bleach-whitelist
When this is successful, the command bench update –patch should succeed.
Next, run the below command to gather all requirements and set them onto your instance:
bench setup requirements
When this is successful, your instance should be accessible. You may however notice that the instance has not loaded assets. To load and compile assets to yout instance, run the following command:
bench build
After this is done successfully, your assets will be setup properly, and your instance will look fine. In some cases, you may get the message that your system is being updated. Please refresh again after a few moments. If you encounter such, its a configuration issue. Open sites/common_site_config.json file and locate maintenance_mode. You will find that its value is set to 1. Change the value to 0, so the value should look as shown below:
You will need to have SSL certificate installed on your instance to keep users of your system safe online. In Frappe Framework or ERPNext, this is a simple process.
Install snapd on your machine
sudo apt install snapd
Update snapd
sudo snap install core; sudo snap refresh core
Remove existing installations of certbot
sudo apt-get remove certbot
Install certbot
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
For one-step automatic ssl installation
sudo certbot --nginx
If you prefer manual installation,. do the following:
sudo certbot certonly --nginx
Certbot packages on your system come with a cron job or systemd timer that will renew your certificates automatically before they expire. So no further steps are required. If necessary, you can test automatic renewal for your certificates by running this command:
sudo certbot renew --dry-run
Wish you all the best.
Fixtures in ERPNext and the Frappe Framework is a tool to help export Data and Settings. When you need to have data migrated to your custom apps, fixtures will come in handy to help you achieve this.
A simple bench export-fixtures command creates a .json file with the information you want to migrate. This information can then be imported to the other application by running the bench migrate command.
Custom fields are also a way to add your custom fields to doctypes created by ERPNext, and ensure your fields will not get erased the next time you upgrade the instance.
In Software, multi-tenancy is an architecture in which a single instance of a software application serves multiple customers, who are called tenants. The application can be offered as a service or as a platform.
Companies today are leveraging software as a service, or SaaS, to provide data protection in a package that results in superior security, better economics and reduced overhead. One of the ways we do this is through multi-tenant architecture.
In today’s video, we will loon at how to implement multi-tenancy in ERPNext and the Frappe Framework.
bench config dns_multitenant on
bench new-site first.site
bench setup nginx
sudo service nginx reload
bench –site first.site install-app erpnext
After this is successful, navigate to /etc/hosts and make the following changes.
Please take into account the name of your sites. You will need to add a route for every site you add.
Add routes:
127.0.0.1 first.site
127.0.0.1 second.site
ERPNext is one of the fastest-growing ERP systems in the marketplace. It has listed in top ERP systems for 3 years in a row (2017, 2018, 2019) according to Gartner.
ERPNext is an open-source technology. This means that they provide the code to people that implement the software, basically, you can do whatever you want with the software. Unlike traditional commercial off-the-shelf software where the code is proprietary, you can’t really change the code without very deep technical expertise. Open-source, allows organizations to change and modify the technology however they need to. ERPNext positions and markets their product as an open-source alternative to SAP.
Having been rated as a category leader by GetApp in 2020, and rated by Gartner for user friendliness, here are 5 reasons to get you started;
ERPNext is an opensource solution. All you need to do is get a company to help you implement it for your business. You can also opt for the enterprise version of ERPNext, which is 10X cheaper that SAP.
The tech giants, the likes of Google, Amazon, Microsoft and even Android phones are being powered by open source software. Get your business into the loop as well.
The choice of where your data sits is yours. You can decide to have it on Dropbox, Google Drive, Amazon S3, or wherever you like it sitting.
Gartner has rated ERPNext top for user friendliness for 3 years in a row. In fact, there is a saying out there that Everyone who uses ERPNext likes it!
This is not the kind of software where you have to rely on one company to provide all the support. Its open-source nature opens you to a wide community where you can get support any time you need it. You may also decide to choose a partner to help you with your work. Frappe Technologies is also a choice if you so desire.