Search code examples
odooqwebodoo-13

KanBan view inherit with QCode


I am trying to customize the kanban view on res.partner

I want to list all category_id associated to the contact without using

<field name="category_id"  widget="many2many_tags" options="{'color_field': 'color', 'no_create_edit': True}" />

I tried to use the Qwep t-foreach loop but doesn't work, why?

<li t-foreach="record.category_id" t-as="item">
    <t t-esc="item_value"/>
</li>

this print

many2many

false

false

[object Object]

false

false

res.users

false

true

false

true

Venditore

[object Object]

7,6

2record

i need to print the name of the res.partner.category

at the same time i need to create a class inside each kanban box with the name of each category_id something like

<div class="oe_kanban_details category_1 category_2">
 ...

thanks


Solution

  • You are looping over record category_id attributes. You got that result because you used the special variable $as_value, those are the actual values of the following attributes.

    type
    change_default
    company_dependent
    context
    depends
    domain
    manual
    readonly
    relation
    required
    searchable
    sortable
    store
    string
    views
    raw_value
    value
    

    The raw_value contains the recordset ids and the value is a string showing the number of records.

    You can try to override the kanban record qweb context to get the category_id data [{'color':, 'display_name':, 'id': }, ...] from recordData object.

    Example

    var KanbanRecord = require('web.KanbanRecord');
    
    KanbanRecord.include({
         _get_M2M_data: function (field) {
            var categories = [];
            if (field in this.recordData && this.recordData[field].data) {
                categories = this.recordData.category_id.data;
            }
            return categories;
         },
         _setState: function (recordState) {
            var self = this;
            this._super(recordState);
            self.qweb_context['get_m2m_data'] = self._get_M2M_data.bind(self);
        },
    });
    

    Then use it in kanban view like following:

    <t t-foreach="get_m2m_data('category_id')" t-as="category_data">
        <t t-esc="category_data.data['display_name']"/>
    </t>
    

    Use the following code to get a similar result when using the field tag:

    <div class="o_kanban_tags_section oe_kanban_partner_categories">
        <span class="oe_kanban_list_many2many">
            <div class="o_field_many2manytags o_field_widget o_kanban_tags">
                <t t-foreach="get_m2m_data('category_id')" t-as="category_data">
                    <span t-att-class="'o_tag o_tag_color_'+ category_data.data['color']"><span></span><t t-esc="category_data.data['display_name']"/>
                    </span>
                </t>
            </div>
        </span>
    </div>