pythonxmlodoo-8kanban

How to access one2many fields values on Kanban view odoo 0.8?


I need to loop over the records of o2m filed in kanban to show what I need from the other model.

all i need in kanban view to do this

<t t-foreach="o2m_field" t-as"record">
    <t t-esc="record.name"/>
</t>

Is that possible to do it?


Solution

  • Yes you can.

    This question is a duplicate to Is it possible to show an One2many field in a kanban view in Odoo? but here is a link to a module from Serpent Consulting which will be able to do what you are looking for.

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

    Here is a little more info.

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

    Many2one values are provided as a tuple. Access the many2one properties like this.

    Many2one ID: <t t-esc="o.partner_id[0]"/>
    Many2one Name: <t t-esc="o.partner_id[1]"/>