Skip to Content
Menu
This question has been flagged
3 Replies
8622 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>
        <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>
                    </t>
                </xpath>
            </field>
         </record>


EDIT #1

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>
                    </t>
                </xpath>
            </field>


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>
                    </t>
                </xpath>
            </field>

I get this error :

Error: NameError: name 'variant' is not defined



Avatar
Discard

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?

Author

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?

Best Answer

Hi,

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:

https://apps.openerp.com/apps/modules/8.0/web_one2many_kanban/

We can go through an example that you can try,


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


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/>
    <br/>
</t>

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.

Thanks.





Avatar
Discard
Author

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

Related Posts Replies Views Activity
0
Feb 23
1790
0
Feb 17
4278
1
Feb 18
6710
1
Nov 24
167
0
Apr 24
44