[Python] Add checkboxes column in Odoo13 tree view

Discussão em 'Python' iniciado por Stack, Março 16, 2025.

  1. Stack

    Stack Membro Participativo

    I'm currently creating a custom Odoo13 module where I want to display a wizard to the user with a table of values, so they can select one or many rows and after clicking a button, perform an action only on the selected rows.

    So far, I was able to create the wizard view and display the many2many field as a table, see image below:

    [​IMG]

    My question is: How can I show a column with checkboxes so the user can select the rows they are interested in?

    I have seen this in a lot of places in odoo base modules, like the following image:

    [​IMG]

    I tried defining the wizard view like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <odoo>
    <data>
    <record id="product_list_dilve_wizard_view" model="ir.ui.view">
    <field name="name">Import product from DILVE</field>
    <field name="model">dilve.import.product.list.wizard</field>
    <field name="arch" type="xml">
    <field name="dilve_records" widget="many2many">
    <tree editable="top" create="false" edit="true"
    decoration-success="type == 'new'"
    decoration-warning="type == 'changed'">
    <field name="isbn" />
    <field name="name" />
    <field name="type" invisible="True" />
    </tree>
    </field>
    <footer>
    <button string="Importar" name="create_product" class="oe_highlight" type="object"/>
    <button name="cancel" string="Cancelar" class="oe_link" special="cancel"/>
    </footer>
    </field>
    </record>

    <record id="product_template_inherited_tree_view" model="ir.ui.view">
    <field name="name">product.template.view.tree.inherit</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_tree_view"/>
    <field name="arch" type="xml">
    <xpath expr="//tree" position="attributes">
    <attribute name="js_class">button_in_tree</attribute>
    </xpath>
    </field>
    </record>
    </data>
    </odoo>


    Tried with multiple widget options and changing the editable, create, edit properties, but none of that worked.

    The javascript function for creating the view is this (I had to do it like this and not xml because I wanted to add the button that triggers the wizard near the "create" odoo button):

    _OpenWizard: function () {
    var self = this;
    this.do_action({
    type: 'ir.actions.act_window',
    res_model: 'dilve.import.product.list.wizard',
    name :'Import data from DILVE',
    view_mode: 'tree',
    view_type: 'form',
    view_id: 'product_list_dilve_wizard_view',
    views: [[false, 'form']],
    target: 'new',
    res_id: false,
    });
    }


    Bonus points: I would also like to know how can I group rows based on the type field. So instead of showing green or yellow, a dropdown row is displayed.

    Thanks!

    Continue reading...

Compartilhe esta Página