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.
It is important to consider this topic since we have been having technology giants around for some time now. More and more are expressing their interests to join the African movement, promising billions of dollars to the highly potent continent. In this article, I will quickly look at the risks we have at hand, the solution that we can employ to mitigate the risks, and where to start to safeguard our interests as individuals, as individual countries and as a continent.
When technology giants started coming to Africa, everyone was happy to have them around. Not long, they started to hire aggressively to meet their tech gaps. The kind of salaries they offered software engineers were so high for local startups to match. The startups started losing employees to the giants. The talents the startups polished over the years started leaving, and the companies had little or nothing to do to keep them. This is still happening and threatening the longevity of the startups.
Technology giants taking away all the good software engineers is not all. Those that remain are hired to work for them in their countries. They allow them to work at the comfort of their homes, work for less hours, and still pay triple the amount our local startups are can keep up with.
The solution to this is to employ ecosystem-level risk management strategies. Governments need to partner with technology companies to train more tech talent. The government’s responsibility will be to provide the necessary infrastructure, while the technology companies provided the relevant curriculum and the needed training.
Code with Karani is a Software Development Training Institution that provides hands on training for software engineers that is propelled by information. The institution is currently purely online, with all content delivered to students through the internet. The current students are not only African but are spread all over the world.
A lead instructor with:
An effective THREE-POINT delivery strategy:
Are you ready to get started? CLICK HERE to Register NOW for FREE!
You can watch the video below.
When I graduated from college and landed a Software Developer job at Futuristic, I was all in. I was so enthusiastic about code that finding time to have my lunch was becoming difficult by the day. I wanted to write these little symbols on my computer that made people’s problems fade away. It was so satisfying. This, however, is a pretty common occurrence, especially in small companies: most junior developers are thrown into the deep end, struggle a bit, learn a lot and use their youthful energy to code and work all over the place.
For most developers, this is not the only case. They want to be involved in developer evangelism, meaning they go for hackathons and conferences in addition to their day job. They also have tonnes of personal projects to work on whenever they have a minute spared. I know, it feels good: it makes one feel like they are growing at a supersonic speed, and say yes to everything.
This wasn’t very different from my case, and I burnt out, hard. Saying yes to everything meant I didn’t have time to rest, reflect on life and have quality personal time.
Unfortunately, burnout is difficult explain to anyone who hasn’t been through it. When I burn’t out, I didn’t want to speak to anyone, and the thought of going to work in the morning made me want to cry (actually, I often did). I thought saying no to people would mean I have let them down, and therefore didn’t have the courage to say so.
On this fateful day my alarm went off at 5.30 A.M as usual, I responded to it, prepared and left my house for work. I waited at the bus stop for a ‘matatu’ as we commonly refer to them in Kenya. When the matatu arrived, I stepped one foot inside, thought for a moment and decided not to board. I went back home and just like that, I had lost all interest in the job and worst of all, quit. This is a situation I wouldn’t want anyone to find themselves in.
This didn’t leave me without a change. It gave me valuable lessons. When I recovered considerably, I decided to try out a different company, speak less and pursue my interests more. This is how I joined Software Technologies. The new resolutions made me much more comfortable in my new role, and this way I realized career growth and completed more enterprise level projects. Since then, I have worked with other companies and have learnt even more about developer burnout.
The most common cause of burnout for software developers is a prolonged state of intense stress, accompanied by a perceived feeling of lack of control. Burnout grows slowly and builds up a little step at the time. I’ve seen it manifest when developers feel stuck working very hard and for long periods on projects that:
Actually some people define this kind of project as a “death march”, a term that for the bigger part describes a preventable reality.
In those conditions, burnout starts taking hold of your life causing progressively worsening feelings of:
A death march is a project that, after the autopsy, usually reveals the following characteristics:
Being on a death march feels like walking in the middle of a railway tunnel, too far from the entrance to run back, and too exhausted to continue moving forward. You see the light in front of you, but you have the feeling that what you see is not sunlight. It comes from an old and rusty locomotive headlamp. You can feel the vibration, and you can hear the train’s whistle. It looks like it is coming at full speed toward you. You realize that you forgot why you even started walking in that tunnel, and you keep getting text messages from your boss asking when you are going to be out of the tunnel, and from your family asking at what time you are going to be back home for dinner.
Burnout enters your life slowly, and manifest itself with symptoms that increase in intensity over time. Those include the following, but this list is definitely not exhaustive. I will keep updating it to make it more exhaustive with time:
It is far easier to stop burnout during the early stages. It is much harder to fix once you’ve been deep in it for weeks or months.
Here are the strategies that I recommend. Note that this is also not all and I will certainly keep adding to it:
You have a boss, and you have a job. Your boss could be a client, a manager, the board, or who knows what else. It doesn’t matter who you report to. Everybody reports to someone or something. What matters is that you are ultimately in control of what you choose to do.
Your boss can choose to fire you if he or she is not happy with your performance. If you do your absolute best, and your boss decides to let you go, maybe it wasn’t meant to be, and you should move forward and do something else. No job is worth losing your health for, and you are responsible for deciding what you need to stay healthy and productive. Most importantly, you are responsible for letting your boss know what you need to be at your best to achieve the best.
If you burnout, your productivity goes down to almost zero, your life becomes miserable, and all your efforts to get your work done were for nothing. If you care about the work you are doing, you need to avoid getting to that point. It will not help you, your career, your family, your team or your client.
We are all different. Nobody knows where your breaking point is. Your boss might be a beast that can work 18 hours a day for years, never eat or sleep and still be productive. That’s commendable, but maybe that’s not you.
If your boss is a gymnast who can perform flips in the air from a standing position, you might be in awe of his or her skills, but you don’t get to that point just because you are asked to stretch. You won’t be able to do it from one day to the next, and you should not give the impression that you commit to doing it with no help if you know it is not possible. You’ll fall on your head and break your neck.
In a given context, you might be more of a 10 hour work day maximum kind of person, imagine that, and you might be one of those people that needs to eat a few times a day and sleep a few hours a night. Go figure.
Regardless of where your “too much” point is, it is your responsibility to make it clear to your boss and the organization you work for. You need to establish your “non-negotiables,” and you must make them clear. Your boss might not tell you, but he or she expects that from you.
You also need to be at peace with the potential consequences of your non-negotiables. If your boss is not happy with your limits, you might not get that promotion or raise that you wanted. You should be okay with that because you already established that you cannot go past your non-negotiables. If your limits are not compatible with your company expectations, you might have to find a place that is more compatible with you.
Keep in mind that if you keep telling everyone “I’ll try,” even if you know that you won’t be successful, you are not doing a favor to your company or your team. Be realistic, and don’t promise things that you know are not going to happen. If you do and fail, you are entirely responsible for it.
On the other hand – and, this is very important – your non-negotiables do not define you. They only establish how you can and should operate in a given context. There are companies and projects where working crazy hours is not a problem. In fact, it can be a lot of fun. I’ve been there, and it is a fantastic experience. It depends on the support you get from the company, the environment, the team, the boss, the reasons for the push, the mission, what is on the horizon and the people you have around.
If you feel like you are with friends and you have a stable support structure around you, what could be unbearable becomes doable. That is why good leadership and a great culture are essential for teams to become highly-performant and operating at their best.
It is your responsibility to communicate to your boss what you and your team need to be successful. If you need more resources, make it clear. If the timeline is too short, make it clear. If the project is too big, make it clear. Be vocal. Don’t make people guess.
Your boss might not always be able to give you what you need. However, if you painted an explicit picture of reality, and you believe that you have good, unselfish and ethical reasons for what you are asking, then you did what you could, and you should be able to sleep soundly at night.
You have heard it one million times and maybe ignored it. There are more books on the topic than letters in this blog post. I’ll just give you the 30 seconds executive summary.
I’ll let the real experts tell you what flavor of each of those points is right for you, but please don’t ignore it. Your brain needs your body to function. You cannot do your best if your body is falling apart. A Ferrari with flat tires is going to lose a race against a Toyota 110.
For some people, life is work. For others, work is life. For the majority, a balance of work and non-work activities is a healthy balance for a happy life.
For example, I have a demanding job and working on a project to which I have become very attached that is very important to me. However, I also want to dedicate myself to other activities outside of work. That includes time with my family, reading, writing articles, teaching programming, hiking, etc. I need it not because I don’t like work. I need it because it makes me better at my job, and happier in general.
Do not sacrifice some of the things you like to do because there is not enough time in your day. Make the time; it will boost your performance at work. Find a right balance, and put it on your list of non-negotiables.
If there is one message that I hope you’ll take away from this post is that you are in control of what you are going to do. Don’t let things happen to you. Eliminate any fatalist view of reality, and take ownership of your actions. Make it clear to everyone what your boundaries are, tell people what you need for you to be successful, and accept that others might not agree with you.
Ultimately, you can’t control what other people do or think, but you can positively influence it. Doing so will go a long way to keep you out of burnout and in control of what railway tunnel you choose to cross.
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.