Odoo中文社区可以通过以下三个域名访问:shine-it.net , odoocn.org,odoo.net.cn

原论坛用户的基本信息和发帖这里都予以保留,请注意:原论坛用户无需重新注册新用户,但是您的密码需要重置

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

在listview的web视图上增加一个按钮的问题



  • 我想在列表页面的web试图上增加一个全局按钮(“更多”按钮需要选中列表项才可以显示,这个不是我希望的),如下图所示:
    [img [检测到链接无效,已移除] attachimg=3][/img]
    xml代码如下:

    <br />&lt;templates&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;t t-extend=&quot;ListView.buttons&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;t t-jquery=&quot;span.oe_alternative&quot; t-operation=&quot;append&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span class=&quot;oe_fade&quot;&gt;or&lt;/span&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;a href=&quot;#&quot; class=&quot;oe_bold oe_list_button_import_lead&quot;&gt;Import Lead&lt;/a&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/t&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp;  &lt;/t&gt;<br />&lt;/templates&gt;<br />
    


    js代码如下:

    <br />&nbsp; &nbsp; var MODELS_NOT_TO_HIDE = &#91;&#039;crm.lead&#039;];<br />&nbsp; &nbsp; instance.web.ListView.include({<br />&nbsp; &nbsp; &nbsp; &nbsp; load_list: function (data) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var self = this;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var add_button = false;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var res_model = this.dataset.model;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!this.$buttons) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; add_button = true;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var ret = this._super.apply(this, arguments);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($.inArray(res_model, MODELS_NOT_TO_HIDE) == -1) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.$buttons.find(&#039;.oe_list_button_import_lead&#039;).remove();//隐藏按钮<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(add_button) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.$buttons.on(&#039;click&#039;, &#039;.oe_list_button_import_lead&#039;, function() {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.do_action({<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  //pop window<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return ret<br />&nbsp; &nbsp; &nbsp; &nbsp; },<br />&nbsp; &nbsp; });<br />
    


    这样可以获得如下图所示的效果:
    [img [检测到链接无效,已移除] attachimg=4][/img]
    那个“或”字无法去掉,因此想在xml中直接使用t-if来判断,满足条件在增加button,否则就不要增加,理论上的代码如下:

    <br />&lt;templates&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;t t-extend=&quot;ListView.buttons&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &lt;t t-if=&quot;widget.options.import_lead_enable !== false&quot;&gt;&nbsp; &lt;!--这是条件判断--&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;t t-jquery=&quot;span.oe_alternative&quot; t-operation=&quot;append&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span class=&quot;oe_fade&quot;&gt;or&lt;/span&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;a href=&quot;#&quot; class=&quot;oe_bold oe_list_button_import_lead&quot;&gt;Import Lead&lt;/a&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/t&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/t&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp;  &lt;/t&gt;<br />&lt;/templates&gt;<br />
    


    但是这种方法会直接报错,Error while extending template 'ListView.buttonsNo expression given, 不论我在js中如何定义import_lead_enable,甚至使用listview原有的参数。
    如果改成如下代码,不会报错,但是t-if永远也不为true,哪怕我将listview原有的参数拿过来都不行。

    <br />&lt;templates&gt;<br />&nbsp; &nbsp;  &lt;t t-if=&quot;widget.options.import_lead_enable !== false&quot;&gt;&nbsp; &lt;!--条件语句在最外面--&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;t t-extend=&quot;ListView.buttons&quot;&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;t t-jquery=&quot;span.oe_alternative&quot; t-operation=&quot;append&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span class=&quot;oe_fade&quot;&gt;or&lt;/span&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;a href=&quot;#&quot; class=&quot;oe_bold oe_list_button_import_lead&quot;&gt;Import Lead&lt;/a&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/t&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/t&gt;<br />&nbsp; &nbsp;  &lt;/t&gt;<br />&lt;/templates&gt;<br />
    



    如果我想在xml中直接条件判断,到底应该如何做呢?
    谢谢



  • 这个 看来只有 buke 大神 能跟你讨论了.

    记得前段时间他 也研究过此处添加 button



  • [quote author=ccdos link=topic=14531.msg25042#msg25042 date=1383287195]
    这个 看来只有 buke 大神 能跟你讨论了.

    记得前段时间他 也研究过此处添加 button
    [/quote]
    buke大神在何方?呼唤大神下凡。



  • 拿到里面来嘛~

    <br />&lt;templates&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;t t-extend=&quot;ListView.buttons&quot;&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;t t-jquery=&quot;span.oe_alternative&quot; t-operation=&quot;append&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;t t-if=&quot;widget.options.import_lead_enable !== false&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span class=&quot;oe_fade&quot;&gt;or&lt;/span&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;a href=&quot;#&quot; class=&quot;oe_bold oe_list_button_import_lead&quot;&gt;Import Lead&lt;/a&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/t&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/t&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/t&gt;<br />&nbsp; &nbsp;  &lt;/t&gt;<br />&lt;/templates&gt;<br />
    


  • 我自己写了一下测试了,找到解决方法了,load_list里面可以remove,那就说明或/按钮已经存在了,也就是说t-if已经执行过了,所以不行,我实验了下,修改到start方法中就可以了,<t t-jquery="span.oe_alternative" t-operation="append">这个你写错了,应该是after,还有,直接判断<t t-if="widget.options.import_lead_enable !== false">,就不需要在remove按钮了,t-if把或和按钮都包含进去就可以了。
    js代码:

    openerp.add_button = function(instance) {<br />&nbsp; &nbsp; var _t = instance.web._t,<br />&nbsp; &nbsp; &nbsp; &nbsp; _lt = instance.web._lt;<br />&nbsp; &nbsp; var QWeb = instance.web.qweb;<br /><br />&nbsp; &nbsp; instance.add_button = {};<br /><br />&nbsp; &nbsp; var MODELS_NOT_TO_HIDE = &#91;&#039;crm.lead&#039;];<br />&nbsp; &nbsp; instance.web.ListView.include({<br />&nbsp; &nbsp; &nbsp; &nbsp; start: function() {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.options.my_btn = true;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.$el.addClass(&#039;oe_list&#039;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return this._super();<br />&nbsp; &nbsp; &nbsp; &nbsp; },<br />&nbsp; &nbsp; });<br />}
    


    xml代码:

    &nbsp; &nbsp; &lt;t t-extend=&quot;ListView.buttons&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;t t-jquery=&quot;span.oe_alternative&quot; t-operation=&quot;after&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;t t-if=&quot;widget.options.my_btn&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span class=&quot;oe_fade&quot;&gt;or&lt;/span&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;a href=&quot;#&quot; class=&quot;oe_bold oe_list_button_import_lead&quot;&gt;Import Lead&lt;/a&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/t&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/t&gt;<br />&nbsp; &nbsp; &lt;/t&gt;
    


  • 还有一个问题就是,这样写全局不好吧,我想能不能在你需要添加页面,重载js文件,只修改本页面,不修改全局,请教。



  • 直接include listview就好了。
    instance.web.ListView.include({
            load_list: function () {
                var self = this;
                this._super.apply(this, arguments);
                var b_length= self.__parentedParent.$el.find('.ok_bn').length;
                if(b_length ==0 && self.model=="res.partner"){ //通过获取this中的对象信息进行分析最终确定在那个地方加按钮。
                    console.log(self.$buttons[0].firstChild.className!="oe_button ok_bn");
                    console.log(+b_length<=0+"ok_bnok_bnok_bnok_bnok_bnok_bnok_bn");
                    var button = $("服务");
                    root=self.$el.parents();
                    button.prependTo(root.find('.oe_list_buttons'));
                    this.$buttons.on('click', '.ok_bn', function() {
                        self.do_action({
                            type: 'ir.actions.act_window',
                            res_model: "product.product",
                            res_id: 1,
                            views: [[false, 'form']],
                            target: 'current',
                            context:"",
                        }, {
                            on_reverse_breadcrumb: function () {
                                self.reload();
                            }
                        });
                    });
                } 
            },
        });
    但是不推荐这么做。不符合odoo的思想。有旭哥(http://odoo.nbzx.me) 找到一个一个好方法。
    (推荐使用)

            <record id="action_purchase_need" model="ir.actions.act_window">
                <field name="name">采购 </field>
                <field name="res_model">purchase.need</field>
                <field name="view_type">form</field>
                <field name='view_mode'>tree_purchase_need</field>
                <field name="view_id" ref="purchase_need_tree"/>
            </record>


        instance.web.views.add('tree_purchase_need', 'instance.web.dftg_ext.NeedListView');
        instance.web.dftg_ext.NeedListView = instance.web.ListView.extend({
            init: function() {
                var self = this;
                this._super.apply(this, arguments);
                this.on('list_view_loaded', this, function() {
                    if(self.__parentedParent.$el.find('.oe_purchase_need').length == 0){
                        var button1 = $("<button type='button' class='oe_button oe_purchase_need'>刷新采购需求</button>")
                            .click(this.proxy('do_refresh_action'));
                        self.__parentedParent.$el.find('.oe_list_buttons').append(button1);
                    }
                });
            },
            do_refresh_action: function () {
                var self = this;
                var action_manager = new instance.web.ActionManager(self);

                return action_manager.do_action('dftg_ext.action_purchase_need_refresh_wizard', {
                            on_close: function () {
                                self.do_search(self.last_domain, self.last_context, self.last_group_by);
                            }
                });
            },
            //重载列表数据
            do_search: function(domain, context, group_by) {
                var self = this;
                this.last_domain = domain;
                this.last_context = context;
                this.last_group_by = group_by;
                this.old_search = _.bind(this._super, this);
                return self.old_search(new instance.web.CompoundDomain(self.last_domain), self.last_context, self.last_group_by);
            },
        });



  • [quote author=开阖-静静 link=topic=14531.msg31382#msg31382 date=1447298909]
    直接include listview就好了。
    instance.web.ListView.include({
            load_list: function () {
                var self = this;
                this._super.apply(this, arguments);
                var b_length= self.__parentedParent.$el.find('.ok_bn').length;
                if(b_length ==0 && self.model=="res.partner"){ //通过获取this中的对象信息进行分析最终确定在那个地方加按钮。
                    console.log(self.$buttons[0].firstChild.className!="oe_button ok_bn");
                    console.log(+b_length<=0+"ok_bnok_bnok_bnok_bnok_bnok_bnok_bn");
                    var button = $("服务");
                    root=self.$el.parents();
                    button.prependTo(root.find('.oe_list_buttons'));
                    this.$buttons.on('click', '.ok_bn', function() {
                        self.do_action({
                            type: 'ir.actions.act_window',
                            res_model: "product.product",
                            res_id: 1,
                            views: [[false, 'form']],
                            target: 'current',
                            context:"",
                        }, {
                            on_reverse_breadcrumb: function () {
                                self.reload();
                            }
                        });
                    });
                } 
            },
        });
    但是不推荐这么做。不符合odoo的思想。有旭哥(http://odoo.nbzx.me) 找到一个一个好方法。
    (推荐使用)

            <record id="action_purchase_need" model="ir.actions.act_window">
                <field name="name">采购 </field>
                <field name="res_model">purchase.need</field>
                <field name="view_type">form</field>
                <field name='view_mode'>tree_purchase_need</field>
                <field name="view_id" ref="purchase_need_tree"/>
            </record>


        instance.web.views.add('tree_purchase_need', 'instance.web.dftg_ext.NeedListView');
        instance.web.dftg_ext.NeedListView = instance.web.ListView.extend({
            init: function() {
                var self = this;
                this._super.apply(this, arguments);
                this.on('list_view_loaded', this, function() {
                    if(self.__parentedParent.$el.find('.oe_purchase_need').length == 0){
                        var button1 = $("<button type='button' class='oe_button oe_purchase_need'>刷新采购需求</button>")
                            .click(this.proxy('do_refresh_action'));
                        self.__parentedParent.$el.find('.oe_list_buttons').append(button1);
                    }
                });
            },
            do_refresh_action: function () {
                var self = this;
                var action_manager = new instance.web.ActionManager(self);

                return action_manager.do_action('dftg_ext.action_purchase_need_refresh_wizard', {
                            on_close: function () {
                                self.do_search(self.last_domain, self.last_context, self.last_group_by);
                            }
                });
            },
            //重载列表数据
            do_search: function(domain, context, group_by) {
                var self = this;
                this.last_domain = domain;
                this.last_context = context;
                this.last_group_by = group_by;
                this.old_search = _.bind(this._super, this);
                return self.old_search(new instance.web.CompoundDomain(self.last_domain), self.last_context, self.last_group_by);
            },
        });
    [/quote]
      😉 静静 你是男是女?



  • 我也想静静



  • 静静的方法学习了。。



  • [quote author=开阖-静静 link=topic=14531.msg31382#msg31382 date=1447298909]
    直接include listview就好了。
    instance.web.ListView.include({
            load_list: function () {
                var self = this;
                this._super.apply(this, arguments);
                var b_length= self.__parentedParent.$el.find('.ok_bn').length;
                if(b_length ==0 && self.model=="res.partner"){ //通过获取this中的对象信息进行分析最终确定在那个地方加按钮。
                    console.log(self.$buttons[0].firstChild.className!="oe_button ok_bn");
                    console.log(+b_length<=0+"ok_bnok_bnok_bnok_bnok_bnok_bnok_bn");
                    var button = $("服务");
                    root=self.$el.parents();
                    button.prependTo(root.find('.oe_list_buttons'));
                    this.$buttons.on('click', '.ok_bn', function() {
                        self.do_action({
                            type: 'ir.actions.act_window',
                            res_model: "product.product",
                            res_id: 1,
                            views: [[false, 'form']],
                            target: 'current',
                            context:"",
                        }, {
                            on_reverse_breadcrumb: function () {
                                self.reload();
                            }
                        });
                    });
                } 
            },
        });
    但是不推荐这么做。不符合odoo的思想。有旭哥(http://odoo.nbzx.me) 找到一个一个好方法。
    (推荐使用)

            <record id="action_purchase_need" model="ir.actions.act_window">
                <field name="name">采购 </field>
                <field name="res_model">purchase.need</field>
                <field name="view_type">form</field>
                <field name='view_mode'>tree_purchase_need</field>
                <field name="view_id" ref="purchase_need_tree"/>
            </record>


        instance.web.views.add('tree_purchase_need', 'instance.web.dftg_ext.NeedListView');
        instance.web.dftg_ext.NeedListView = instance.web.ListView.extend({
            init: function() {
                var self = this;
                this._super.apply(this, arguments);
                this.on('list_view_loaded', this, function() {
                    if(self.__parentedParent.$el.find('.oe_purchase_need').length == 0){
                        var button1 = $("<button type='button' class='oe_button oe_purchase_need'>刷新采购需求</button>")
                            .click(this.proxy('do_refresh_action'));
                        self.__parentedParent.$el.find('.oe_list_buttons').append(button1);
                    }
                });
            },
            do_refresh_action: function () {
                var self = this;
                var action_manager = new instance.web.ActionManager(self);

                return action_manager.do_action('dftg_ext.action_purchase_need_refresh_wizard', {
                            on_close: function () {
                                self.do_search(self.last_domain, self.last_context, self.last_group_by);
                            }
                });
            },
            //重载列表数据
            do_search: function(domain, context, group_by) {
                var self = this;
                this.last_domain = domain;
                this.last_context = context;
                this.last_group_by = group_by;
                this.old_search = _.bind(this._super, this);
                return self.old_search(new instance.web.CompoundDomain(self.last_domain), self.last_context, self.last_group_by);
            },
        });
    [/quote]


    因为我是对一个对象写多个不同的视图,我在图一中这样指定view_id,没有找到,所以我又在下面按图二的方式又指定了一下,按钮就不显示了,请问这个怎么解决???



  •     //修正odoo自定义view_mode不会取得view_id的问题
        instance.web.ViewManagerAction.include({
            init: function(parent, action) {
                var self = this;
                if (!action.views[0][0] && action.view_id){
                    if (action.views[0][1] == action.view_mode){
                        action.views[0][0] = action.view_id[0]
                    }
                }
                return this._super.apply(this, arguments);
            }
        });


    试试这段代码,不知道好用不.



  • [quote author=Smile佳佳 link=topic=14531.msg32198#msg32198 date=1461296520]
    [quote author=开阖-静静 link=topic=14531.msg31382#msg31382 date=1447298909]
    直接include listview就好了。
    instance.web.ListView.include({
            load_list: function () {
                var self = this;
                this._super.apply(this, arguments);
                var b_length= self.__parentedParent.$el.find('.ok_bn').length;
                if(b_length ==0 && self.model=="res.partner"){ //通过获取this中的对象信息进行分析最终确定在那个地方加按钮。
                    console.log(self.$buttons[0].firstChild.className!="oe_button ok_bn");
                    console.log(+b_length<=0+"ok_bnok_bnok_bnok_bnok_bnok_bnok_bn");
                    var button = $("服务");
                    root=self.$el.parents();
                    button.prependTo(root.find('.oe_list_buttons'));
                    this.$buttons.on('click', '.ok_bn', function() {
                        self.do_action({
                            type: 'ir.actions.act_window',
                            res_model: "product.product",
                            res_id: 1,
                            views: [[false, 'form']],
                            target: 'current',
                            context:"",
                        }, {
                            on_reverse_breadcrumb: function () {
                                self.reload();
                            }
                        });
                    });
                } 
            },
        });
    但是不推荐这么做。不符合odoo的思想。有旭哥(http://odoo.nbzx.me) 找到一个一个好方法。
    (推荐使用)

            <record id="action_purchase_need" model="ir.actions.act_window">
                <field name="name">采购 </field>
                <field name="res_model">purchase.need</field>
                <field name="view_type">form</field>
                <field name='view_mode'>tree_purchase_need</field>
                <field name="view_id" ref="purchase_need_tree"/>
            </record>


        instance.web.views.add('tree_purchase_need', 'instance.web.dftg_ext.NeedListView');
        instance.web.dftg_ext.NeedListView = instance.web.ListView.extend({
            init: function() {
                var self = this;
                this._super.apply(this, arguments);
                this.on('list_view_loaded', this, function() {
                    if(self.__parentedParent.$el.find('.oe_purchase_need').length == 0){
                        var button1 = $("<button type='button' class='oe_button oe_purchase_need'>刷新采购需求</button>")
                            .click(this.proxy('do_refresh_action'));
                        self.__parentedParent.$el.find('.oe_list_buttons').append(button1);
                    }
                });
            },
            do_refresh_action: function () {
                var self = this;
                var action_manager = new instance.web.ActionManager(self);

                return action_manager.do_action('dftg_ext.action_purchase_need_refresh_wizard', {
                            on_close: function () {
                                self.do_search(self.last_domain, self.last_context, self.last_group_by);
                            }
                });
            },
            //重载列表数据
            do_search: function(domain, context, group_by) {
                var self = this;
                this.last_domain = domain;
                this.last_context = context;
                this.last_group_by = group_by;
                this.old_search = _.bind(this._super, this);
                return self.old_search(new instance.web.CompoundDomain(self.last_domain), self.last_context, self.last_group_by);
            },
        });
    [/quote]


    因为我是对一个对象写多个不同的视图,我在图一中这样指定view_id,没有找到,所以我又在下面按图二的方式又指定了一下,按钮就不显示了,请问这个怎么解决???
    [/quote]
    除了上楼静静的方法,还有一个方法,在action中添加<field name="context">{'tree_view_ref': '包名.视图id'}</field>