Odoo Help


How could my action catch the res_id from this kanban view?

Pascal Tremblay
on 3/18/17, 3:55 PM 1,311 views

Hello all,

On the product.template kanban view, for each product, I see all default_code of the associated variants.

If I click on one of this code, an empty form view opens instead of the form view of the clicked variant.

How could I open the form view with the right variant id?

I have tried passing the variant.id with the context, but I don't manage it.

Should I declared my action in PYthon instead of XML?

XML of the kanban and the action when we click a code :

<record id="product_variant_action_2" 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="view_mode">form</field>
            <field name="view_type">form</field>
<!--         <field name="res_id" eval="context.get('res_id')"/>-->
            <field name="context">{}</field>
            <field name="search_view_id" ref="product.product_search_form_view"/>
            <field name="view_id" eval="False"/> <!-- Force empty -->
            <field name="domain" eval="False"/> <!-- Force empty -->
        <record id="product_template_kanban_view_inherited" model="ir.ui.view">
            <field name="name">Product.template.kanban.view.inherited</field>
            <field name="model">product.template</field>
            <field name="inherit_id" ref="product.product_template_kanban_view" />
            <field name="arch" type="xml">
                <xpath expr="//div[@name='tags']" position="after">
                     <t t-foreach="record.product_variant_ids.raw_value" t-as="variant">
                        <a name="%(product_variant_action_2)d" context="{'res_id': variant.id}"
                            type="action">[<t t-esc="variant.default_code"/>]</a>


I have defined a new python method to open my product variant in the current window. It takes the res_id from the context.

With this code, it opens the product variant id 1362 in a new form view. So my action works well :

<field name="arch" type="xml">
                <xpath expr="//div[@name='tags']" position="after">
                     <t t-foreach="record.product_variant_ids.raw_value" t-as="variant">
                        <a name="open_product_variant" context="{'res_id': 1362}" type="object">[<t t-esc="variant.id"/>
<t t-esc="variant.default_code"/>]</a>

With this code, what I would want, I get an error :

<field name="arch" type="xml">
                <xpath expr="//div[@name='tags']" position="after">
                     <t t-foreach="record.product_variant_ids.raw_value" t-as="variant">
                        <a name="open_product_variant" context="{'res_id': variant.id}" type="object">[<t t-esc="variant.id"/>
                           <t t-esc="variant.default_code"/>]</a>

I get this error :

Error: NameError: name 'variant' is not defined

I've been looking for this also but i havent found any solution yet, so i declared the action in my python instead. I'd love to know whether this is possible or not, and if it is, how?

Muhammad Irfan
on 3/19/17, 5:32 AM

My action in Python is almost ready, but I'm not able to pass the variant id correctly to the action. Could I see your line please?

Pascal Tremblay
on 3/19/17, 9:12 AM

Hilar AK

--Hilar AK--
--Hilar AK--



Experienced Odoo developer, Functional Consultant. Happy to help in the development and also functional consultation.

Hilar AK
On 3/19/17, 11:39 PM


In kanban views, you can loop through a one2many field, but you wouldn't get the values.  There is still some issues with the On2many in kanban views.So You can't do this operation without a customized stuff.

So please download and install addon from below link and try the below steps:


We can go through an example that you can try,

 <field name="one2manyFieldname"/>
  <t t-name="kanban-box">
  <div class="oe_kanban_content">
  <t t-foreach="record.one2manyFieldname.raw_value" t-as='o'>
  <t t-esc="o.name"/><br/>

The important part is before the template tag you have to pass through your one2many field so it is available within your template. Then you must access the record's "raw_value" and give it an alias. Like this.

<t t-foreach="record.one2manyFieldname.raw_value" t-as='o'>

Then you can access the properties of the record.
Within the scope of the t-foreach tag you can access properties of the record, like this.

<t t-foreach="record.one2manyFieldname.raw_value" t-as='o'>
    ID: <t t-esc="o.id"/><br/>
    Name: <t t-esc="o.name"/><br/>
    Write Date: <t t-esc="o.write_date"/><br/>
    Write UID: <t t-esc="o.write_uid"/><br/>
    Some Property: <t t-esc="o.some_property"/><br/>

You should be able to access the properties of each record you have aliased (in this case as 'o'). Do not take the above too literally. The layout and styling of your html and css are up to you. As well as the properties of your record you choose to display.


This module web_one2many_kanban is already intalled and that work well. The problem is when I try to create a link (<a>) to display one variant. Impossible to pass the o,id in context. Thank for your answer

Pascal Tremblay
on 3/20/17, 10:10 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/18/17, 3:55 PM
Seen: 1311 times
Last updated: 3/19/17, 11:39 PM