Odoo Help


How to define and incorporate external web view type/mode?

Moritz Ringler
on 9/30/14, 6:08 PM 2,485 views

I'm currently working on a personalized leaves summary. For that, I have to incorporate my own external view (QWeb and JavaScript code to be used on the client side). It's quite similar to what happens in web_gantt or web_kanban, however, doing it like they do only brought me so far. Seems like those are rooted more deeply in the core. Yet, there must be a possibility to extend the view types without fiddling with the core?

Here is what I got so far:

The file barchart.js contains the view type definition, points to the template and stores the whole thing as a new view:

openerp.mr_holidays = function (instance) {
var _t = instance.web._t,
   _lt = instance.web._lt;
var QWeb = instance.web.qweb;
instance.web.views.add('barchart', 'instance.mr_holidays.BarChartView');

instance.mr_holidays.BarChartView = instance.web.View.extend({
    display_name: _lt('BarChart'),
    template: "BarChartView",
    view_type: "barchart",


That seems to load fine, and the view should be available on the client side.

Now I define an action that uses my newly defined "barchart" view by setting it in the view_mode:

<record model="ir.actions.act_window" id="...">
            <field name="res_model">hr.holidays</field>
            <field name="view_type">form</field>
            <field name="view_mode">barchart</field>
            <field name="view_id" eval="view_holiday_barchart"/>

But now it seems impossible to define an "ir.ui.view" for the action! I get the error message:

No default view of type 'barchart' could be found !

Makes sense, since there is no default view and I didn't tell it which fields to use, right? However, I don't seem to find any documentation as how to define that view. More specificly, I would now need to have a tag to use in my view arch definition, quite similar to <gantt>, where I can specify fields and options to my barchart, e.g.

<record model="ir.ui.view" id="view_holiday_barchart">
       <field name="model">hr.holidays</field>
       <field name="arch" type="xml">
             <barchart date_start="date_from" date_stop="date_to"  />

However, that does not work (same error as above). Weirdly enough, if I change the view_mode in the action to gantt I get the expectet gantt chart, even if the required options are given in the <barchart> tag, not in <gantt>.

I spent quite some time on this, but I'm not making any progress. Please help

In your example, eval="view_holiday_barchart" should have been ref="view_holiday_barchart" but it doesn't work anyway.

Jérôme Thériault
on 5/24/17, 8:23 AM
Moritz Ringler
On 10/14/14, 12:25 PM

Ok, took some time, but I seem to have found the solution. Turns out the view_id definition in the action does work when defining a Gantt, but not in my self defined web view. It works when I specify the view by context:

<record model="ir.actions.act_window" id="...">
        <field name="res_model">hr.holidays</field>
        <field name="view_type">form</field>
        <field name="view_mode">barchart</field>
        <field name="context">{
            'barchart_view_ref' : 'mr_holidays.view_holiday_barchart'

The key is built by adding "_view_ref" to the view type's name and the value is a fully qualified id (as it must contain the module name).

v10 here. I went through a lot of code and tried many things, probably you also tried, but this seems to be the only way. This wasn't needed in v8, only view_mode was. I wonder what happened...

Jérôme Thériault
on 5/24/17, 8:25 AM

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: 9/30/14, 6:08 PM
Seen: 2485 times
Last updated: 3/16/15, 8:10 AM