OpenERP always displays inherited view instead of original

回眸只為那壹抹淺笑 提交于 2019-12-30 06:23:09

问题


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.


回答1:


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.




回答2:


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>



回答3:


There may not be a possibility to make an inherited form the standard form of your model so that it will be presented automatically.

BUT If you look at a specific task --> open an inherited form view for a one2many field e.g.; there is. Set the context variable 'form_view_ref' to 'MODULE.VIEW_ID'.

<field name="myOne2ManyField" context="{'form_view_ref': 'myModule.myInheritedView'}/>

Still works with Odoo 9.0.



来源:https://stackoverflow.com/questions/10880535/openerp-always-displays-inherited-view-instead-of-original

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!