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
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?
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?