As we know, once a year odoo always changes their versions. Every time they change the version there is always feature that changing, either added or removed, in good or bad way. Therefore, as an odoo programmer, I try not to memorize odoo code, even code that is often used, such as creating an Action Window. I have tried to memorize the Action Window creation code before, but I didn’t continue to doing it in recent days, because it’s useless. I have realised in the latest odoo version there are some changes at Action Window creation code, making my memorization in the previous version become irrelevant. Moreover, at this time, besides working on projects with the latest version of odoo, I am also still working on several projects with the old version.
Now I always try to read the odoo source code, then copy it. Even to make the Model I copy and paste from the odoo source code. Ha..ha..ha. During module development, I always open the Sublime Text Editor for at least 2 windows. The first window is used to open the original odoo source code, while the second window is used to open the code that I develop. Isn’t it more difficult ? Odoo source code is thousands of lines, right ?
I have my own trick about how to read the odoo source code. In my experience, this method is quite effective and can make my job easier. So, I will share these tricks to you in a special thread, namely Read Odoo Source Code. In this thread, the content is more or less about the question: if there is an action on odoo, where is it written in their source code ? Hopefully useful.
In this first part, I’ll cover where and how a sidebar is written in the odoo source code. If you don’t know, what I mean about the sidebar is two dropdowns that labeled Print and Action that usually exist in the List and Form View as shown below.
As an example, I will discuss where the source code for the Mark Quotation as Sent button in the sales order above is written. You should know that this tutorial is written on odoo 14 enterprise edition. In other odoo versions the button may not exist, but I think the way to find where the sidebar button is written is same.
With google chrome open your odoo Sales menu. If you are opening List View you must select one or more records to make Action button appear. Then open google chrome developer tool, by right clicking on the window then select Inspect. Or press the F12 key on the keyboard.
Then open the Network tab on the google chrome’s developer tool. Make sure the Network tab is clean, as shown below. If there is some data, clean it first by pressing the circle crossed button in the left corner of the google chrome’s developer tools.
Then click the Action button on odoo and select Mark Quotation as Sent.
From the Network tab of google chrome’s developer tool, we can see that when we click the Mark Quotation as Sent button, the browser will call the controller namely /web/action/load with the results as shown below. What turned out to be an Action Server.
If you’ve read my tutorial on how to create an Action Server (read here), I’m sure You already know how to call the Action Server from the Menu Item. Now you know that Action Server can also be called from the Sidebar / Action Menu.
Then where is the code of the Mark Quotation as Sent button is written in original odoo source code ?
To find out where the button’s code is written in the odoo source code, we can use the GREP command that comes with linux. I have wrote a tutorial about how to use the GREP command at this article.
At the terminal, navigate to the odoo addons directory. On my computer the directory is located at /odoo14/odoo14-server/addons then execute GREP command with keywords from the /web/action/load controller results which is called by the browser when we click the Mark Quotation as Sent button before. In this case I use the value of the key xml_id, which is model_sale_order_action_quotation_sent. The result is as shown below.
Now we know, that the code for the Mark Quotation as Sent sidebar button is written in the sale/views/sale_views.xml file, now let’s open the file and take a look at the contents.
The picture above is the contents of the sale/views/sale_views.xml file, where the Mark Quotation as Sent sidebar button is written in the original odoo source code. Now you can copy it to your own code, if you want to add a new button in the Sidebar / Action Menu.