Odoo13自定义向导树视图添加复选框列及实现行分组的方法问询
Odoo13自定义向导树视图添加复选框列及实现行分组的方法问询
我正在创建一个自定义Odoo13模块,想要给用户展示一个带表格的向导,让用户可以选择一行或多行,点击按钮后只对选中的行执行操作。
目前我已经创建了向导视图,并且把many2many字段显示成了表格,如下所示:
[向导树视图截图:未显示复选框列的产品列表,包含ISBN、名称等字段,部分行根据type字段显示绿色或黄色装饰]
我的问题是:如何添加一个带复选框的列,让用户可以选择感兴趣的行?
我在Odoo基础模块里见过这个功能,比如这样的效果:
[Odoo基础模块示例截图:树视图首列显示每行对应的复选框,用户可勾选选择]
我尝试这样定义向导视图:
<?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>
我试过多种widget选项,也修改过editable、create、edit属性,但都没用。
触发向导的JavaScript函数是这样的(因为要在Odoo原生“创建”按钮附近添加触发向导的按钮,所以用JS实现而不是XML):
_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, }); }
额外需求: 我还想知道如何根据type字段对行进行分组,不是用绿色或黄色高亮,而是显示可展开/收起的分组行。
谢谢!
备注:内容来源于stack exchange,提问作者Alberto M
相关产品推荐
相关产品推荐

