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 do you define specific (not default) views for each view mode type (form, tree, etc.) in act_window xml?

By
John Baldwin
on 2/12/15, 3:19 PM 2,681 views

I can't understand how to define specific views for each view mode... This is what I want to do:

in my act_window record I have "<field name="view_mode">tree,form</field>" defining that tree and form views are needed. I want to use "my_custom_tree_view" and "my_custom_form_view" for those types respectively. I've tried using a filed called "views" with (name, type) pairs. I've tried using "view_ids" the same way. I've tried using multiple "view_id" with ref's and that doesn't work.... Can someone please show me an example of assigning custom views to multiple view modes please?

<record model="ir.actions.act_window" id="test_action"> 
<field name="name">A Test Action</field> 
<field name="res_model">some.model</field>
<field name="view_mode">tree, form</field>
<!-- a field to describe my specific tree view and form view -->          <<<<<---- HELP ME HERE! 
</record>

1

Temur

--Temur--
2896
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
On 2/13/15, 3:07 AM

You can specify view to use as follows:

<field name="view_id" ref="the_xml_id_of_view"/> -just xml id if the view is in the same module

<field name="view_id" ref="module_name.the_xml_id_of_view"/> -external xml id if the view is in another model (pay attention to the dot notation)

You can also specify custom search view:

<field name="search_view_id" ref="xml_id_or_external_xml_id_as_needed"/>

Also you can manipulate default views using sequence="N" property, by setting lower N than it is in the active default view.

Big Thanks @ Temur

+1

Ankit H Gandhi(AHG)
on 7/8/16, 6:30 AM
0
james_p
On 12/4/16, 3:26 AM

Please check this code from product module. This should answer the question.


<record id="product_variant_action" model="ir.actions.act_window">            
    <field name="name">Product Variants</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">product.product</field>
    <field name="context">
        {'search_default_product_tmpl_id': [active_id],
        'default_product_tmpl_id': active_id}
    </field>
    <field name="search_view_id" ref="product_search_form_view"/>
    <field name="view_ids" eval="[(5, 0, 0),
        (0, 0, {'view_mode': 'tree'}),
        (0, 0, {'view_mode': 'form', 'view_id': ref('product_variant_easy_edit_view')}),
        (0, 0, {'view_mode': 'kanban'})]"/>
    <field name="help" type="html">
        <p class="oe_view_nocontent_create">
            Click to define a new product.
        </p>
    </field>
</record>
0
Arsenty Karamurza
On 6/16/16, 3:17 AM

I'll explain with an example:

This is a menuitem with an action associated to it.

<menuitem name="Measurement Sheets" id="cirem_measurements" parent="cirem_proposition" action="action_measurements" sequence="540"/>

..but it's not a simple xml-defined action:

    <record id="action_measurements" model="ir.actions.server">
<field name="name">Measurement Sheets</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="state">code</field>
<field name="code">action = self.my_measurements(cr, uid, context=context)</field>
<field eval="True" name="condition"/>
</record>

you see, it refers to code, which uses another action as a template for creating a custom action that has specific views assigned to each particular view type (kanban, tree, form)

so, firstly, here goes an action used as a template:

        <record id="action_measurements_base" model="ir.actions.act_window">
<field name="name">Measurement Sheets</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.order</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field name="domain">[('state', 'in', ('sent', 'draft', 'sale'))]</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to fill in a new measurement sheet based on the measurement template.
</p><p>
Odoo will help you efficiently handle the complete sales flow:
quotation, sales order, delivery, invoicing and payment.
</p>
</field>
</record>


The most interesting part is the code that sets different view ids to each view type (based on the template-action):

(notice how one can redefine other action's properties too)

    def my_measurements(self, cr, uid, context=None):
IrModelData = self.pool['ir.model.data']
actionObject = IrModelData.xmlid_to_object(cr, uid, 'cirem.action_measurements_base', context=context)
action = actionObject.read(['name', 'help', 'res_model', 'target', 'domain', 'context', 'type', 'search_view_id'])
if not action:
action = {}
else:
action = action[0]
# action['name'] = 'Measurements' SET OTHER PROPERTIES LIKE THIS
tree_view_id = IrModelData.xmlid_to_res_id(cr, uid, 'sale.view_order_tree')
form_view_id = IrModelData.xmlid_to_res_id(cr, uid, 'cirem.measurements_view')
action.update({
'views': [
[tree_view_id, 'tree'],
[form_view_id, 'form'],
[False, 'graph'],
[False, 'calendar'],
[False, 'pivot']
],
})
return action

Ta-Da! Please let me know if I can be of any more help to you :)

0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 2/12/15, 5:54 PM

The easiest way is if you define additional ir.ui.view, separate for tree and form, like this (in effect three records):

     <record model="ir.actions.act_window" id="test_action"> 
       <field name="name">A Test Action</field> 
       <field name="res_model">some.model</field>
       <field name="view_type">form</field>
       <field name="view_mode">tree, form</field>
    </record>

    <record model="ir.ui.view" id="some_name_form">
      <field name="name">some_name_form</field>
      <field name="model">some.model</field>
      <field name="arch" type="xml">
        <form>
            <field name="name"/>
        </form>
      </field>
    </record>

    <record model="ir.ui.view" id="some_name_tree">
      <field name="name">some_name_tree</field>
      <field name="model">some.model</field>
      <field name="arch" type="xml">
        <tree>
            <field name="name"/>
        </tree>
      </field>
    </record>

 

Thanks for the answer, but it does not solve the problem of multiple form/tree views and selecting the proper one.

John Baldwin
on 2/12/15, 7:32 PM

Why not solve? views not wroks? error? you have a menu which call test_action?

zbik
on 2/13/15, 3:03 AM

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: 2/12/15, 3:19 PM
Seen: 2681 times
Last updated: 12/4/16, 3:26 AM