在我的模块中,我想在树视图中创建一个按钮,该视图显示按月分组的项。因此,为了创建这个按钮,我添加了以下代码:
<t t-extend="ListView">
<t t-jquery=".o_list_view" t-operation="before">
<button type="button" class="btn btn-primary btn-sm oe_my_own_button" accesskey="c">
<t>Month</t>
</button>
</t>
</t>
我添加了这个javascript:
odoo.define('randa_gamification.filter', function (require) {
"use strict";
var ListView = require('web.ListView');
ListView.include({
render_buttons: function($node) {
var self = this;
this._super($node);
this.$buttons.on('click', '.oe_my_own_button', this.proxy('custom_button_view_action'));
},
custom_button_view_action: function () {
this.do_action({
type: "ir.actions.act_window",
res_model: "gamification.goal",
view_type : 'tree',
view_mode : 'form,tree',
context : '{"search_default_group_by_month": True}',
});
}
});
});
我在assets_backend模板中实现了这段代码。按钮被添加到我的视图中,但它不会运行该操作。谢谢。
发布于 2018-03-02 17:25:12
为此,您需要使用一个小Javascript:
ListView.include({
render_buttons: function($node) {
var self = this;
this._super($node);
this.$buttons.find('.oe_my_own_button').click(this.proxy('custom_button_view_action'));
},
custom_button_view_action: function () {
this.do_action({
type: "ir.actions.act_window",
res_model: "gamification.goal",
views: [[false,'form']],
target: 'new',
view_type : 'form',
view_mode : 'form',
});
}
});
更新
我使用不同的模板,主要是因为它使我的Javascript代码更简单。
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_button_add" t-operation="before">
<button type="button" class="btn btn-primary btn-sm oe_my_own_button" accesskey="c">
<t>Month</t>
</button>
</t>
</t>
请注意,您需要将oe_my_own_button
类添加到按钮。
发布于 2018-03-02 16:49:23
您可以通过在模块中定义一个搜索视图来创建groupby,如下所示:
<record id="view_id" model="ir.ui.view">
<field name="name">view.name</field>
<field name="model">model.name</field>
<field name="arch" type="xml">
<search string="">
<field name="month"/>
<group expand="0" string="Group By">
<filter string="Month" icon="terp-go-month" domain="[]" context="{'group_by': 'month'}"/>
</group>
</search>
</field>
</record>
https://stackoverflow.com/questions/49071565
复制