Enable Dark Mode!
how-to-add-an-icon-in-systray-in-odoo-16.jpg
By: Syamili K

How to Add an Icon in Systray in Odoo 16

Technical Odoo 16

In Odoo, the systray icon is used to provide quick access to certain functionality or to display notifications to the user. The systray icon is shown in the notification bar, and it is located in the top right corner of the user interface. The systray displays notifications and alerts for various events, such as incoming messages, reminders, etc.

The default icons include a username and a drop-down list linked to the installed app launcher icon. The options available in the menu depend on the specific module or application being used.

The below-marked area in the screenshot shows the systray icons in Odoo.

how-to-add-an-icon-in-systray-in-odoo-16-1-cybrosys

Now let’s check how to create a systray in the menu bar and set an action for it. Firstly we need to create a directory, and inside that, create a static folder and add a JS and XML folders in it.

how-to-add-an-icon-in-systray-in-odoo-16-2-cybrosys

Next, make the view for the systray icon in the notification bar. In the XML code, provide a template name. And in the <i> tag have a class with icon name as fa-shopping-cart and set style for this icon. This will display a shopping cart icon there.

<?xml version="1.0" encoding="UTF-8" ?>
<templates>
 <t t-name="PurchaseOrderSystray">
     <div class="new_icon">
            <div class="icon_div">
                <div class="toggle-icon" role="button">
                    <i id='create_order' class="fa fa-shopping-cart fa-1.5x"
                       style="color: white; margin-bottom:10px; padding:13px;"      role="img" aria-label="Purchase Order"/>
                </div>
            </div>
     </div>
 </t>
</templates>

The template will add a shopping cart image on the topbar of Odoo with white color, and set padding for it to align this icon in line with existing icons. The fa-1.5x specifies the size of the icon.

Next step is to add an action for that icon, for that need js code. Here adding a function for. While clicking on the button, it will pop up a wizard and open a new form for creating a purchase order.

/** @odoo-module **/
import SystrayMenu from 'web.SystrayMenu';
import Widget from 'web.Widget';
var PurchaseOrder = Widget.extend({
  template: 'PurchaseOrderSystray',
  events: {
      'click #create_order': '_onClick',
  },
  _onClick: function(){
      this.do_action({
           type: 'ir.actions.act_window',
           name: 'Purchase Order',
           res_model: 'purchase.order',
           view_mode: 'form',
           views: [[false, 'form']],
           target: 'new'
      });
  },
});
SystrayMenu.Items.push(PurchaseOrder);
export default PurchaseOrder;

Adding action for this icon, first, we want to import the Widget and SystrayMenu classes. In Odoo JavaScript, we can extend existing classes using the extend method. This method allows you to create a new class that inherits all the properties and methods of the original class, and can override or add new properties and methods.

Here extending the Widget class by creating a new class called Purchase Order. It adds a new widget to our systray icon. Then specify the template name as our XML template name. The events mention a _onClick function to the widget. In the click event function, we specified a do_action for opening a purchase order in a new form.

After creating the files, give it to the assets in the manifest file.  Here mention the path of the files in web.assets_frontend.

'assets': {
       'web.assets_frontend': [
           'website_scroll_bottom_to_top/static/src/js/website_scroll_button.js',
           'website_scroll_bottom_to_top/static/src/css/website_scroll_button.css',
       ],
   },

And finally, let’s install the module and check the result.

how-to-add-an-icon-in-systray-in-odoo-16-3-cybrosys

After installing the app, in the above image we can see the shopping cart button is added to the notification bar. If we click on that icon, a wizard will popup that shows a new form view of the purchase order.

how-to-add-an-icon-in-systray-in-odoo-16-4-cybrosys

Next, we can just fill the form with the vendor name and add some products, then save the order.

how-to-add-an-icon-in-systray-in-odoo-16-5-cybrosys

Check in the purchase module, and we can see a new record will be created there.

how-to-add-an-icon-in-systray-in-odoo-16-6-cybrosys


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



0
Comments



Leave a comment

 


whatsapp
location

Calicut

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

location

London

Cybrosys Limited
Alpha House,
100 Borough High Street, London,
SE1 1LB, United Kingdom

location

Kochi

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

location

Bangalore

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

Send Us A Message