odoo10在顶部“创建”按钮附加增加自定义按钮

来源:互联网 发布:淘宝定制商品怎么拍 编辑:程序博客网 时间:2024/05/30 23:03

HOW TO ADD BUTTON IN TREE VIEW HEADER NEAR “CREATE” AND “IMPORT” BUTTONSODOO10


来自:https://supportuae.wordpress.com/2017/09/06/how-to-add-button-in-tree-view-header-near-create-and-import-buttons-odoo10/


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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
odoo.define('tree_menu.tree_view_button',function(require){
"use strict";
 
 
varcore = require('web.core');
varListView = require('web.ListView');
varQWeb = core.qweb;
 
 
ListView.include({      
     
        render_buttons:function($node) {
                varself = this;
                this._super($node);
                    this.$buttons.find('.o_list_tender_button_create').click(this.proxy('tree_view_action'));
        },
 
        tree_view_action:function() {          
                 
        this.do_action({              
                type:"ir.actions.act_window",              
                name:"product",              
                res_model:"product.template",              
                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, create tree_menu/static/src/xml/tree_view_button.xml with the template, which replaces “Create” button if I use project.project model

1
2
3
4
5
6
7
8
9
<?xmlversion="1.0"encoding="UTF-8"?>
      <templateid="template"xml:space="preserve">      
          &lt;tt-extend="ListView.buttons">                  
            &lt;tt-jquery="button.o_list_button_add"t-operation="replace">                          
                  <buttont-if="widget.model == 'purchase.order'" class="btn btn-primary btn-sm o_list_tender_button_create" type="button">Create Tender</button>
                  <buttont-if="widget.model != 'purchase.order'" class="btn btn-primary btn-sm o_list_button_add" type="button">Create</button>
            &lt;/t>      
          &lt;/t>  
      </template>

3). After that, add js script in web.asset_backend (Create file tree_menu/views/tree_view_asset.xml)

1
2
3
4
5
6
7
8
9
10
<?xmlversion="1.0"encoding="utf-8"?>  
<odoo>      
      <data>          
            <templateid="assets_backend"name="tree view menu" inherit_id="web.assets_backend">              
                  <xpathexpr="."position="inside">                  
                        <scripttype="text/javascript"src="/tree_menu/static/src/js/tree_view_button.js"></script>              
                  </xpath>          
            </template>      
      </data>  
</odoo>

4). And finally, add in __manifest__.py section ‘qweb’ for ‘qweb’: [‘static/src/xml/tree_view_button.xml’], and place file views/project.xml in ‘data’ section.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
    'name': 'odoo10 Tree View JS Menu',
    'version': '1.0',
    'category': 'General',
    'summary': 'odoo10 Tree View JS Menu',
    'description': """ odoo10 Tree View JS Menu """,
    'author': 'Ananthu',
    'website': 'http://www.codersfort.com',
    'depends': ['base','purchase','web'],
    'data':[
            'views/tree_view_asset.xml',
            ],
    'qweb': ['static/src/xml/tree_view_button.xml'],      
    'demo': [],
    'installable': True,
    'application': True,
    'auto_install': False,
}


阅读全文
0 0
原创粉丝点击