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

OpenErp 专栏收录该内容
79 篇文章 0 订阅

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


来自: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" ;
 
 
var core = require( 'web.core' );
var ListView = require( 'web.ListView' );
var QWeb = core.qweb;
 
 
ListView.include({      
     
         render_buttons: function ($node) {
                 var self = 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
<? xml version = "1.0" encoding = "UTF-8" ?>
       < template id = "template" xml:space = "preserve" >      
           &l t ;t t-extend = "ListView.buttons" >                  
             &l t ;t t-jquery = "button.o_list_button_add" t-operation = "replace" >                          
                   < button t-if = "widget.model == 'purchase.order'" class = "btn btn-primary btn-sm o_list_tender_button_create" type = "button" >Create Tender</ button >
                   < button t-if = "widget.model != 'purchase.order'" class = "btn btn-primary btn-sm o_list_button_add" type = "button" >Create</ button >
             &l t ;/t>      
           &l t ;/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
<? xml version = "1.0" encoding = "utf-8" ?>  
< odoo >      
       < data >          
             < template id = "assets_backend" name = "tree view menu" inherit_id = "web.assets_backend" >              
                   < xpath expr = "." position = "inside" >                  
                         < script type = "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
    点赞
  • 3
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值