Odoo Help

Welcome!

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

0

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

By
Moritz Ringler
on 9/30/14, 6:08 PM 1,580 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

0
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'
        }</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).

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/30/14, 6:08 PM
Seen: 1580 times
Last updated: 3/16/15, 8:10 AM