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>
            </t>
        </div>
    </t>
</templates>
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.
