本文主要是介绍odoo10在顶部“创建”按钮附加增加自定义按钮,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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, } |
这篇关于odoo10在顶部“创建”按钮附加增加自定义按钮的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!