odooodoo-12

Custom widget js doesn't recognize template from qweb


I try to test custom widget from js reference and I get error in debugger:

Error: QWeb2: Template 'some.template' not found

qweb.xml was properly set in manifest, because when I extend ListController and use another template, it works correctly.

Here is template definition, which I use in qweb.xml:

<?xml version="1.0" encoding="UTF-8"?>
<template>
    <div t-name="some.template">
        <span class="val"><t t-esc="widget.count"/></span>
        <button>Increment</button>
    </div>
</template>

I tried to change <template> -> <templates>, totally removed tag "template" but still get the same error message.

JS:

odoo.define('working.test', function (require) {
var Widget = require('web.Widget');
var Counter = Widget.extend({
    template: 'some.template',
    events: {
        'click button': '_onClick',
    },
    init: function (parent, value) {
        this._super(parent);
        this.count = value;
    },
    _onClick: function () {
        this.count++;
        this.$('.val').text(this.count);
    },
});

// Create the instance
var counter = new Counter(this, 4);
// Render and insert into DOM
counter.appendTo(".o_nocontent_help");

})

Manifest:

# -*- coding: utf-8 -*-
{
    'name': "testwidget",

    'summary': """
        Short (1 phrase/line) summary of the module's purpose, used as
        subtitle on modules listing or apps.openerp.com""",

    'description': """
        Long description of module's purpose
    """,

    'author': "My Company",
    'website': "http://www.yourcompany.com",

    # Categories can be used to filter modules in modules listing
    # Check https://github.com/odoo/odoo/blob/12.0/odoo/addons/base/data/ir_module_category_data.xml
    # for the full list
    'category': 'Uncategorized',
    'version': '0.1',

    # any module necessary for this one to work correctly
    'depends': ['base'],
    'qweb': ['static/qweb.xml'],

    # always loaded
    'data': [
        # 'security/ir.model.access.csv',
        'views/views.xml',
        'views/web_asset.xml',
    ],
    # only loaded in demonstration mode
    'demo': [
        'demo/demo.xml',
    ],
}

Any idea how I need to modify this template to make the widget working correctly and in which table in db odoo stores these templates?


Solution

  • I was running into this same issue and needed to put my QWeb code into static/src/xml/base.xml in order for Odoo to recognize it.

    You can check to see if Odoo is loading the QWeb by going to this URL on your Odoo instance:

    <odoo_instance>/web/webclient/qweb?mods=<my_module_name>
    

    Such as:

    localhost:8069/web/webclient/qweb?mods=test
    

    For comparison, you can see a successful output by using mods=web to load the QWeb assets for the web module.