如何在“创建”附近的树视图标题中添加按钮和“导入”按钮Odoo 8? [英] How to add button in tree view header near "Create" and "Import" buttons Odoo 8?

查看:598
本文介绍了如何在“创建”附近的树视图标题中添加按钮和“导入”按钮Odoo 8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在表单视图标题或树状视图行中成功添加按钮,但是我想在树形视图标题中添加一个自定义按钮,在Odoo 8的创建和导入按钮旁边。我该怎么做?



解决方案

<我找到了我的问题的解决方案!如果我使用project.project模型,则替换创建按钮。


$ b $ 1)我使用点击侦听器为我的按钮创建了一些js脚本( static / src / js / task_list.js ):

  openerp.project =函数(实例){
var QWeb = openerp.web.qweb;
_t = instance.web._t;
var self = this;
openerp.web.ListView.include({
load_list:function(data){
this._super(data);
if(this。$ buttons){$ b $ ('。oe_new_button')。off()。click(this.proxy('do_the_job'));
console.log('Save& Close button method call ...' );
}
},
do_the_job:function(){
this.do_action({
type:ir.actions.act_window,
name:Созданиеновогопроекта,
res_model:project.project,
views:[[false,'form']],
target:'current',
view_type:'form',
view_mode:'form',
flags:{'form':{'action_buttons':true,'options':{'mode':'edit'}}}
});
return {
'type':'ir.actions.client',
'tag':'reload',
}
}
});
}



<2>然后创建 static / src / xml / project_button .xml with template,如果使用project.project模型替换Create按钮

 <?xml version =1.0encoding =UTF-8?> 
< template id =templatexml:space =preserve>
< t t-extend =ListView.buttons>
< t t-jquery =button.oe_list_addt-operation =replace>
< button t-if =widget.model =='project.project'class =oe_button oe_new_button oe_highlighttype =button>Создатьновыйпроект< / button>
< button t-if =widget.model!='project.project'class =oe_button oe_list_add oe_highlighttype =button>Создать< / button>
< / t>
< / t>
< / template>

3)然后我在web.asset_backend中添加我的js脚本(我创建了项目文件/views/project.xml

 <?xml version =1.0encoding =utf-8 >?; 
<! - vim:fdn = 3:
- >
< openerp>
< data>
< template id =assets_backendname =项目资产inherit_id =web.assets_backend>
< script type =text / javascriptsrc =/ project / static / src / js / task_list.js>< / script>
< / xpath>
< / template>
< / data>
< / openerp>

4)最后我添加项目/ __ openerp__.py节'qweb' /src/xml/project_button.xml ,代表静态/ src / js / task_list.js ,并将文件 views / project.xml 放入'数据部分。

 'data':[$ b $'security / project_security.xml',
...
'views / project.xml',
],
'qweb':['static / src / xml / project_button.xml',],
...
'js':'static / src / js / task_list.js',

我的按钮成功替换project.project模型中的旧按钮。


I can successfully add buttons in form view header or in tree view rows, but I want to add a custom button in the treeview header near "Create" and "Import" buttons in Odoo 8. How can I do this?

解决方案

I find solution of my problem! I replace create button if I use project.project model.

1) I create some js script (static/src/js/task_list.js) with click listener for my button :

 openerp.project = function (instance){
    var QWeb = openerp.web.qweb;
    _t = instance.web._t;
    var self = this;
openerp.web.ListView.include({
    load_list: function(data) {
        this._super(data);
        if (this.$buttons) {
            this.$buttons.find('.oe_new_button').off().click(this.proxy('do_the_job')) ;
            console.log('Save & Close button method call...');
        }
    },
    do_the_job: function () {
        this.do_action({
            type: "ir.actions.act_window",
            name: "Создание нового проекта",
            res_model: "project.project",
            views: [[false,'form']],
            target: 'current',
            view_type : 'form',
            view_mode : 'form',
            flags: {'form': {'action_buttons': true, 'options': {'mode': 'edit'}}}
        });
        return {
                'type': 'ir.actions.client',
                'tag': 'reload',
        }
}
});
}

2) After that I create static/src/xml/project_button.xml with template, which replace "Create" button if I use project.project model

    <?xml version="1.0" encoding="UTF-8"?>
<template id="template" xml:space="preserve">
    <t t-extend="ListView.buttons">
                <t t-jquery="button.oe_list_add" t-operation="replace">
                        <button t-if="widget.model == 'project.project'"  class="oe_button oe_new_button oe_highlight" type="button">Создать новый проект</button>
                        <button t-if="widget.model != 'project.project'" class="oe_button oe_list_add oe_highlight" type="button">Создать</button>
        </t>
    </t>
</template>

3) After that I add my js script in web.asset_backend (I create file project/views/project.xml)

    <?xml version="1.0" encoding="utf-8"?>
<!-- vim:fdn=3:
-->
<openerp>
    <data>
        <template id="assets_backend" name="project assets" inherit_id="web.assets_backend">
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/project/static/src/js/task_list.js"></script>
            </xpath>
        </template>
    </data>
</openerp>

4) And finally I add in project/__openerp__.py section 'qweb' for static/src/xml/project_button.xml, 'js' for static/src/js/task_list.js and place file views/project.xml in 'data' section.

    'data': [
        'security/project_security.xml',
         ...
        'views/project.xml',
    ],
    'qweb': ['static/src/xml/project_button.xml',],
    ...
    'js': 'static/src/js/task_list.js',

And my button successful replace old button in project.project model.

这篇关于如何在“创建”附近的树视图标题中添加按钮和“导入”按钮Odoo 8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆