Odoo Help


How to use custom widgets in tree views ?

on 4/3/14, 12:23 PM 8,045 views

I would like to store a period of time in minutes and display it to the user formatted like [hours]h[minutes] in OpenERP 7. Later I would like to allow users to modify the period in this format, so a field function isn't enough. I choose to create a custom widget that will do the formatting and later add a JavaScript TimePicker.

It works fine in form views but not in tree views, the init() of the widget is never called.

I configured the widget as follow:

myview.xml :

<!-- (...) -->
<field name="the_time" widget="hour"/>
<!-- (...) -->

static/js/xml/mymodule.xml :

openerp.mymodule  = function(instance) {

    instance.mymodule.FieldHour = instance.web.form.AbstractField.extend({

        init: function() {
            this._super.apply(this, arguments);
            this.set("value", "");

        render_value: function() {
            val       = this.get("value");
            minutes   = val % 60;
            hours     = Math.round((val - minutes) / 60);

            if (minutes <= 9) {
                minutes = "0" + minutes;

            if (hours <= 9) {
                hours = "0" + hours;

            this.$el.text(hours + "h" +  minutes);


    instance.web.form.widgets.add('hour', 'instance.mymodule.FieldHour');

static/src/xml/mymodule.xml :

<templates id="template" xml:space="preserve">
    <t t-name="FieldHour">
        <div class="oe_field_hour">
            <t t-if="! widget.get('effective_readonly')">
                <input type="text"></input>

It seems related to OpenERP Web Client Bug #666427 but it's a quite old bug. I would be surprised if anyone else ran into this problem and found a workaround.


Leonardo Donelli

--Leonardo Donelli--
| 5 4 8
Roma, Italy
--Leonardo Donelli--

Physics student and part-time developer.

Leonardo Donelli
On 6/18/14, 4:41 AM

Your custom widget is a form view custom widget: you extend web.form.AbstractField which is defined in web/addons/web/static/src/js/view_form.js and defines components used in form views. in the same directory you'll find view_list.js, view_list_editable.js and view_tree.js.

In particular in view_list.js you'll find "column definitions" for various type of fields, you could try working on those to recreate a tree view equivalent of your custom form field widget.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 4/3/14, 12:23 PM
Seen: 8045 times
Last updated: 3/22/16, 12:49 AM