Enable Dark Mode!
By: Risha Ct

How to Add Log Messages from UI in Odoo


In this blog, we are going to learn how to add log messages from the user interface. Adding proper log messages to a particular action helps to keep a record of that action. It will be useful in cases where we need to know the details of the action performed including the date at which it was performed or the user involved in it etc. So when we add a log message in the action, the log detail records corresponding to the action will be created in settings -> technical -> logging where we can view all the recorded actions and it will include details like date of performing the action, database name, user id, log message, etc. In this example, We will add a log message using server action. First, we need to create a server action and then add the log message to it. 
For this, activate developer mode and go to settings -> technical -> server actions. Here we are creating a new server action for updating the name of a product to the name of product + selling price.
We set the action name as ‘update name with price’. This name will be displayed on the action menu on the product page. Next, we specified the model as ‘product template’ to indicate that this action is to be applied to the product. template model. Then in the ‘Action to do’ we selected execute python code. Now a tab named python code will be displayed in the form where we can write the python code for updating the product name. 
In the python code tab, we can see that there is some commented information on the possible attributes that we can give. Here we can see that we have an option to add a log message. By using this, first, let us add a log message that the product name is updated. We can do this by adding the required message as a log("Product name updated", level='info').
Now if we go to inventory -> products -> products we can see the newly created action (update name with price) in the action menu.
When we click on this action, the product name gets updated with price and the log message also gets created.
To see the log message, go to settings -> technical -> logging. We can see a new record got created there with the message “Product name updated” that we added a log message in the newly created server action.
Instead of the text, we can also add meaningful messages such as adding the updated name of the product to the message. To do this we can go to the same server action in settings -> technical -> server actions and update the log message.
So this time, we have updated the log message to display the updated product name along with the message ‘product name updated’. Now when we update the name of a product record as before, the log message will have the product’s new name also. To check this, update the product record from Inventory -> products -> products and go to settings -> technical -> logging. 
We can see that a new record has been created. The last log message recorded will be displayed on the top in the list view. When we open it, we can see that the log message has been created by including the product name with it.
Here we can see that the logging form contains all details including the database name, created date, the id of the user who performed the action, the type of action, action name, and the log message. Similar to how we created the server action, we can also add log messages to automated actions and scheduled actions using the same method.

If you need any assistance in odoo, we are online, please chat with us.


Leave a comment




Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message