Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenERP always displays inherited view instead of original

Tags:

openerp

Original views:

<record id='view_1' model='ir.ui.view'>
    <field name="name">view.name</field>
    <field name="model">my.object</field>
    <field name="priority" eval="17"/>
    <field name="type">form</field>
    <field name="arch" type="xml">
        ...
    </field>
</record>

inherited view from the original:

<record id='view_2' model='ir.ui.view'>
    <field name="name">view.name</field>
    <field name="model">my.object</field>
    <field name="priority" eval="10"/>
    <field name="inherit_id" ref="view_1"/>
    <field name="type">form</field>
    <field name="arch" type="xml">
        ...
    </field>
</record>

So what happens is OpenERP always displays the inherited view ignoring the priority value. Is this expected behaviour, or there's something else I am missing?

If this is the expected behaviour, then please read further :-)

I have my.second.object with many2one field to my.object, and when I want to create my.object from this field, I want to open a bit different form view of my.object. I am trying to create a different view just for that purpose, but as you see it doesn't work so easily (or does it?).

Any help is appreciated.

like image 770
and3p Avatar asked Jun 04 '12 11:06

and3p


2 Answers

Yes it is the expected behavior. The priority of a view only serves to select the main view to use when no specific view was requested. Inherited views are "patch views" that act like children of the view they inherit from, and may never be selected as "main views". They always apply on top of their parent view when that view is displayed.

If you want an alternative view for a certain model you should define a new stand-alone view that does not inherit from any other. If that view is meant to be used only in the context of the view of my.second.object, there are two common tricks to make OpenERP use it:

  • Define it inline in the form view of my.second.object, as a child of the <field> element. This may not work in all OpenERP clients depending on the version, and works best for declaring inline form views for o2m lines, normally.
  • Declare it as a stand-alone view with a low priority (e.g. 32) and put a magic context key in the many2one field of the my.second.object view that should use it. The magic key is in the form <view_type>_view_ref, and the value must be the XML ID of the desired view. This should work everywhere.
<!-- Example 1: inline form view -->
<form string="My second object">
   <field name="my_object_id">
       <form string="My object inline view">
           <field name="name"/>
       </form>
   </field>
 </form>

<!-- Example 2: explicitly ask for special view using magic key -->
<form string="My second object">
   <field name="my_object_id" context="{'form_view_ref': 'module.my_object_form2'}"/>
</form>

For reference, have a look at this page of the OpenERP documentation that explains most of the options for making and using context-specific views.

NOTE: If you have used form_view_ref and from form view if you have any button which is opening another form view of some other model then it will give you error . It will try to open the same form view you have passed in form_view_ref for another model also.

like image 166
odony Avatar answered Sep 18 '22 09:09

odony


What "position" you defined in <field name="field_from_original_view">?

<record id='view_2' model='ir.ui.view'>
    <field name="name">view.name</field>
    <field name="model">my.object</field>
    <field name="priority" eval="10"/>
    <field name="inherit_id" ref="view_1"/>
    <field name="type">form</field>
    <field name="arch" type="xml">
        <field name="field_from_original_view" position="after" (or before)>
            <field name="inherit1" />
            <field name="inherit2" />
            <field name="inherit3" />
        </field>
    </field>
</record>
like image 30
voy Avatar answered Sep 20 '22 09:09

voy