This question has been flagged
1 Reply
6551 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"/>
</record>

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"  />
       </field>
</record>

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

Avatar
Discard

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

Author Best Answer

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'
        }</field>
</record>

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).

Avatar
Discard

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...