Skip to Content
मेन्यू
This question has been flagged
3 Replies
11730 Views

I have an one2many image field that currently shows images in a tabular style. What I want to do is to show it in a card style like a kanban card or in a thumbnail style view.

 

This is my current code:

    class VariantsLines(models.Model):
    _inherit = 'product.variants.lines'

    product_image_360_ids = fields.One2many('product.image.360', 'product_tmpl_id', string='Images')
    display_360_image = fields.Boolean(string='Display 360 Image')


class ProductImage360(models.Model):
    _name = 'product.image.360'
    _order = 'sequence'

    name = fields.Char(string='Name', readonly=False)
    image = fields.Binary(string='Image', attachment=True, readonly=False)
    product_tmpl_id = fields.Many2one('product.template', string='Related Product', copy=True)
    sequence = fields.Integer(string="Sequence", readonly=False)

view.xml

    <field name="inherit_id" ref="jewellery.view_product_variants_lines_form"/>
            <field name="arch" type="xml">
                <xpath expr="//form" position="inside">
                    <div>
                        <group>
                            <field name="display_360_image"/>
                        </group>

                        <group string="Images for 360 view" attrs="{'invisible': [('display_360_image', '=', False)]}">
                            <field name="product_image_360_ids" nolabel="1"
                                   context="{'default_product_tmpl_id': active_id}">
                                <tree create="true" editable="bottom">
                                    <field name="sequence" widget="handle" readonly="0"/>
                                    <field name="name" readonly="0"/>
                                    <field name="image" widget="image" class="oe_left oe_avatar" readonly="0"/>
                                </tree>
                            </field>
                        </group>
                    </div>
                </xpath>
            </field>
Avatar
Discard
Best Answer

Hi,
Just replace the XML with the below code

<field name="arch" type="xml">
<xpath expr="//form" position="inside">
<div>
<group>
<field name="display_360_image"/>
</group>

<group string="Images for 360 view" attrs="{'invisible': [('display_360_image', '=', False)]}">
<field name="product_image_360_ids" nolabel="1"
context="{'default_product_tmpl_id': active_id}">
<kanban>
<field name="id"/>
<field name="sequence"/>
<field name="name"/>
<field name="image"/>
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_global_click">
<div class="o_kanban_image">
<img t-att-src="kanban_image('product.image.360', 'image', record.id.raw_value)"
alt="Image"/>
</div>
<div class="oe_kanban_details">
<ul>
<li class="mb4">
<h5>
<field name="name"/>
</h5>
</li>
<li>
<div t-if="record.sequence.value">
<field name="sequence"/>
</div>
</li>

</ul>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</group>
</div>
</xpath>
</field>

Regards

Avatar
Discard
Author

@Cybrosys Thanks for your help, it worked but it has created some issues.

1. Now when I am creating a record it shows my many2one field on the view :

product_tmpl_id = fields.Many2one('product.template', string='Related Product', copy=True)

I have tried to make it invisible by the attribute invisible = true in python. Also, that field was not in my view so I explicitly included that field in the view and tried invisible = true in XML as well but it didn't work either and the relational field is visible on creating the record.

2. The other is that when I am selecting the image the image doesn't show up after selecting but it only shows up after I save the record (it was not in the case of tree view)

Author

However, I have changed the field product_tmpl_id to readonly=True so it can not be edited. But there must be some way to hide it as well.

Best Answer

What works for me:

context="{'default_name': name}" mode="kanban" options="{'create_text':' '}"
nolabel="1" invisible="0" />

Avatar
Discard
Author Best Answer

@Cybrosys Thanks for your help, it worked but it has created some issues.

1. Now when I am creating a record it shows my many2one field on the view : 
product_tmpl_id = fields.Many2one('product.template', string='Related Product', copy=True)

I have tried to make it invisible by the attribute invisible = true in python. Also,  that field was not in my view so I explicitly included that field in the view and tried invisible = true in XML as well but it didn't work either and the relational field is visible on creating the record.

2. The other is that when I am selecting the image the image doesn't show up after selecting but it only shows up after I save the record (it was not in the case in tree view)

3. There is no way to delete a kanban, if I mistakenly save a record there is no way to delete that (like it shows in action or any other option)

Avatar
Discard
Author

resolved delete issue through this: <kanban delete="true"> . . .

.

.

<a t-if="! read_only_mode" type="delete" style="position: absolute; right: 0; padding: 4px; diplay: inline-block">X</a>

Related Posts Replies Views Activity
3
सित॰ 21
10609
0
अप्रैल 16
2402
1
जुल॰ 20
4758
1
जून 19
5923
1
फ़र॰ 19
6156