This question has been flagged
1 Reply
11757 Views

Hey guys, I'm trying to create a custom module and every thing works fine so far. My only problem is, that I'm not able to show the user avatar in the kanban view. I only get a randow image (maybe my function is wrong?) I trying to get the user avatar from res.partners.

Here the pythonscript:

def _get_user_image(self, cr, uid, ids, field, arg, context=None):
        res = {}
        ctx = {}
        records = self.browse(cr, uid, ids, context=context)
        for record in records:
            res[record.id] = record.user_id.pool.get('res.partner')._get_default_image(cr, uid, False, ctx, colorize=True)
        return res

#...

_columns    = {
        'image'     : fields.function(_get_user_image, type="binary", method=True, string='Image', readonly=True),
    }

The view.xml

<record model="ir.ui.view" id="view_gcon_access_kanban">
    <field name="name">gcon.access.kanban</field>
    <field name="model">gcon.access</field>
    <field name="arch" type="xml">
        <kanban>
            <field name="user_id"/>
            <field name="name"/>
            <field name="count_contact"/>
            <field name="count_devices"/>
            <field name="image"/>
            <templates>
                <t t-name="kanban-box">
                    <div class="oe_kanban_vignette oe_semantic_html_override">
                        <a type="open">
                             <img t-att-src="kanban_image('gcon.access', 'image', record.id.value)" class="oe_kanban_image"/>
                        </a>
                        <div class="oe_kanban_details">
                            <h4>
                                <a type="open">
                                    <field name="user_id"/> (<field name="name"/>)
                                </a>
                            </h4>
                            <group>
                                Contacts: <field name="count_contact"/><br />
                                Devices: <field name="count_devices"/>
                            </group>
                        </div>
                    </div>
                </t>
            </templates>
        </kanban>
    </field>
</record>

What of these codes is wrong? In the xml I tried several tag, but nothing worked or rather displayed the wrong image. We are using the openERP v7. Best regards

Dyck

Avatar
Discard
Author Best Answer

I have found a solution. I used following tag to get the user avatar:

<img t-att-src="kanban_image('res.users', 'image_small', record.user_id.raw_value)" class="oe_kanban_image"/>

Best Regards

Dyck

Avatar
Discard

works also with res.partner

odoo v8