fbpx

I have seen at openERP forum , many have asked the same question and since i also went to the forum or web site or google to look for the solutions , and i got the solutions , i am thinking to share here so that some of you can customize with more confidence with openERP ,
The original documents has this information , which will stay true until version 6.1 ,for 6.2 Aka Version 7 , have to refer back to OpenERP but if you stay tuned , i will try to update , but NO PROMISE O !  ok , let get started …
The search_view_id field in an action definition is used to specify the search view to use, not theform view, as the name implies. If you want to use a specific form view you should use the view_idfield instead (which is used to specify the main view to open, typically a form or tree one). And by the way all the view selection fields in an OpenERP action definition may be overridden by specifying aviews field: an ordered list of pairs (view_id, view_mode) where view_id can be False to use the default view. This is a computed field that the framework automatically adds on regular actions, but may be manually added to a custom action returned by a Python method.
Here is how you could do it in a Python method:
# assuming partner_id, context, form_view_id are defined here

return {

   
'type': 'ir.actions.act_window',

   
'view_type': 'form',

   
'view_mode': 'form,tree',

   
'res_model': 'res.partner',

   
'res_id': int(partner_id),

   
'context': context,

   
'view_id': form_view_id,


   
# optionally, you could refine by specifying the 'views' explicitly

   
'views': [(form_view_id, 'form'),  # open my form view first,

             
(False, 'tree')]         # then default tree view

}

You will find a lot of similar examples in the source code of the official addons, search for code returning'views' or 'view_id'.
The document is very informatic but lacking of a complate examples with explaination and here is My Examples :

STEP 1  – To define a new FORM view.
STEP 2  – To define a new TREE view.
STEP 3  – To define a new SEARCH /FILTER view 
STEP 4  – To define a Window actions 
STEP 5 –  To define an action link to your FORM
STEP 6 –  To define an action link to your TREE
STEP 7 –  To define a Menu that link to your Window Action defined Step 4.

STEP 1 to define a FORM view for the object.

<record model=”ir.ui.view id=”view_egl_object_form>
       <field name=”name>egl.emplr.kdn.form</field>
       <field name=”model>egl.employer.kdn_application</field>
       <field name=”type>form</field>
      <field name=”arch type=”xml>
      <form string=”egl.object.form>
      <notebook colspan=”4>
     <page string=”Application Information>
          <separator string=”‘Information’ colspan=”4 />
          <field name=”name colspan=”4 select=”1 />
          <field name=”issued_date />
          <field name=”expiry_date />
          <field name=”employer_id colspan=”4 select=”1 group=”True />
          <field name=”qty colspan=”4 select=”1 />
          <field name=”bal colspan=”4 select=”1 />
   </page>
     <page string=”Notes>
           <field colspan=”4 name=”comment nolabel=”1 />
   </page>
     <page string=”Worker(s)>
          <separator string=”‘Worker(s)’ colspan=”4 />
          <field name=”foreign_worker_ids colspan=”4 nolabel=”1 select=”1 />
   </page>
    </notebook>
   </form>
   </field>
</record>
 STEP 2 , to define a TREE view for the object
<record model=”ir.ui.view id=”view_egl_object_tree>
         <field name=”name>egl.emplr.kdn.tree</field>
         <field name=”model>egl.employer.kdn_application</field>
         <field name=”type>tree</field>
         <field name=”arch type=”xml>
        <tree string=”egl.object.tree>
          <field name=”name />
          <field name=”employer_id group=”True />
          <field name=”issued_date />
          <field name=”expiry_date />
          <field name=”qty />
          <field name=”bal />
      </tree>
      </field>
</record>
STEP 3 , to define a filter/search view . 
<record id=”view_egl_object_filter model=”ir.ui.view>
       <field name=”name>Employer information Select</field>
       <field name=”model>egl.employer.application</field>
       <field name=”type>search</field>
       <field name=”priority eval=”20 />
      <field name=”arch type=”xml>
      <search string=”Search Detail>
      <group col=”10 colspan=”4>
       <field name=”no />
       <field name=”employer_id />
       <field name=”issued_date />
       <field name=”expiry_date />
    </group>
       <newline />
      <group expand=”0 string=”Group By…>
       <filter string=”No icon=”terp-folder-orange domain=”[]”              context=”{‘group_by’:’no’} />
       <filter string=”Employer icon=”terp-partner domain=”[]  context=”{‘group_by’:’employer_id’} />
    </group>
    </search>
    </field>
</record>
STEP 4 – To define the WINDOW ACTION which has a search view , that point to the ID defined at STEP 3 .
<record id=”action_egl_object model=”ir.actions.act_window>
               <field name=”name>Employer KDN Details</field>
               <field name=”res_model>egl.employer.kdn_application</field>
               <field name=”type>ir.actions.act_window</field>
                <field name=”view_type>form</field>
                <field name=”view_mode>tree,form</field>
                <field name=”search_view_id ref=”view_egl_object_filter />
</record>
STEP 5 – To define action that link to the TREE view defined at STEP 2 and most importantly , it linked with the WINDOWS action defined at STEP 4 with the act_window_id pointing to the ID specified at STEP 4. 
<record id=”view_act_object_tree model=”ir.actions.act_window.view>
                <field name=”view_mode>tree</field>
               <field name=”view_id ref=”view_egl_object_tree />
               <field name=”act_window_id ref=”action_egl_object />
</record>
STEP 6 – To define action that link to the FORM view defined at STEP 1 and most importantly , it linked with the WINDOWS action defined at STEP 4 with the act_window_id pointing to the ID specified at STEP 4. 
<record id=”view_act_object_form model=”ir.actions.act_window.view>
               <field name=”view_mode>form</field>
               <field name=”view_id ref=”view_egl_object_form />
               <field name=”act_window_id ref=”action_egl_object />
</record>
STEP 7 – To define the menu which linked with the window action defined in STEP 4.

<menuitem name=”Employer details id=”menu_egl_object action=”action_egl_object parent=”menu_egl_object_parent />
So far most of the views i created can be called properly , unless it is some inherited object which has its source from resource.resource object where that impacted the employee , user and resources of openerp. I have not yet found any solutions for object require to inherit from hr.employee where it 
stay the same name as hr,employee for the table. I have no problem of calling specific Form / Tree for my new object if the name of the object is different from hr.employee .
Now there are side questions related to what you are trying to do, and you probably want to answer them in addition to solving your immediate issue.
  1. The easiest way to modify an existing view in OpenERP is to inherit it. At first look it seems you’re just trying to a new tab “Connection Info” on the partner form view. It would be trivial (and a lot simpler) to simply create an inherited view that hooks to the  element of the parent view and add an extra  in it. And if you don’t want the tab to be shown in all situations, you can add visibility modifiers to the page with a special attrs attribute.
    Hence the question: why don’t you use this technique here?
  2. When you don’t want to inherit an existing view (because the new view is totally different), the second easiest method is to create a new view of the same type and give it a higher priority (lowerpriority field value). This will automatically replace the default view everywhere this view type is needed. The only cases were it doesn’t work is when a specific view_id is requested by the action that opens the view.
    HOPE users from Malaysia, Singapore or regional SME or anyone from the world will find this topic useful for your continue exploration of openERP and serve your minor customization needs and will be grateful if you could just connect my blog as a friend , just join my members or network of partnership or friends . Growing members encourage me to share more … 
    Cheers and happy using openERP !