view...">

OpenERP always displays an inherited view instead of the original

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, OpenERP always displays the inherited view, ignoring the priority value. Is this the expected behavior or is something else I am missing?

If this is the expected behavior, read on :-)

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

Any help is appreciated.

+7
source share
3 answers

Yes, this is the expected behavior. The priority of the view serves only to select the main view to use when no particular view has been requested. Inherited representations are “patch representations” that act as children of the representation they inherit and can never be selected as “main views”. When this view is displayed, they are always applied on top of their parent view.

If you need an alternative view for a specific model, you must define a new standalone view that does not inherit from any other. If this view is intended to be used only in the context of the my.second.object , there are two general tricks for using OpenCRP:

  • Define it inline as my.second.object as a child of the <field> . This may not work in all OpenERP clients depending on the version and is best suited for declaring inline forms for o2m strings, as a rule.
  • Declare it as a standalone low priority view (e.g. 32) and put the magic context key in the many2one field of the many2one view that should use it. The magic key is in the form <view_type>_view_ref , and the value must be an XML identifier of the required type. 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 help, check out this OpenERP documentation page , which explains most of the options for creating and using context-sensitive views.

NOTE. If you used form_view_ref also from the form view, if you have any button that opens a different form view of another model, then this will give you an error. It will try to open the same form as you also went to form_view_ref for another model.

+14
source

What "position" did you define 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> 
+1
source

It may not be possible to make the inherited form the standard form of your model so that it is automatically presented.

BUT if you look at a specific task -> open the inherited form view for the one2many field, for example. There is. Set the context variable 'form_view_ref' to 'MODULE.VIEW_ID'.

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

Still working with Odoo 9.0.

0
source

All Articles