Chapter 9 - Odoo 15 Development Book

QWeb Templates

In Odoo, there’s a template engine available for the client-side too. This template engine is referred to as Qweb Templates that's applied completely in javascript code and rendered withinside the browser.

Perform the following steps to render a qweb template from client-side;

    1. Import ‘web.core’ and extract qweb reference to a variable like below;

    odoo.define('product_return_pos.order_list_screen',function(require) {
    	"use strict";
    var models = require('point_of_sale.models');
    var gui = require('point_of_sale.Gui');
    var core = require('web.core');
    var QWeb = core.qweb;

    2. Inside the render_list function simply rendered the template like below

            	var contents = this.el.querySelector('.order-list-contents');
            	contents.innerHTML = "";
            	for(var i = 0, len = Math.min(orders.length,1000); i < len; i++){
                	var order	= orders[i];
                	var orderline_html = this.env.qweb.render('OrderLine',{widget: this, order:order});
                	var orderline = document.createElement('tbody');
                	orderline.innerHTML = orderline_html;
                	orderline = orderline.childNodes[1];

    3. Add the template file in static/src/xml/pos_return.xml

    <t t-name="OrderLine" owl="1">
        <tr class="order-line" t-att-data-id="">
            <t t-esc="order.pos_reference"/>
            <t t-if="order.return_ref">
              <t t-esc="order.return_ref"/>
            <t t-esc="order.partner_id[1]"/>
            <t t-esc="order.date_order"/>
            <span class="return-button return_order"      t-on-click="return_click">Return</span>

    4. Then load the Qweb file into the manifest.

    'web.assets_qweb': [

RPC Calls

In Odoo, if we need to call a python function, it can be accomplished by using _rpc calls.

     model: this.model,
     method: 'quick_publish_products',
     args: [this.res_id],
}).then(function (result) {

In the above example, we made an RPC call and invoked the ‘quick_publish_products’ method defined in the current model. Then after invoking the method, the ._rpc will return the data from the method.



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