2017-02-09 58 views
-1

如何在树视图中添加此按钮?
这个代码库/静态/ src目录/ JS /的script.jsAdd button next创建odoo树视图中的按钮

openerp.library = function(instance) { 

    instance.web.ListView.include({ 
     load_list: function(data) { 
      this._super(data); 
      if (this.$buttons) { 
       this.$buttons.find('.oe_my_button').off().click(this.proxy('do_the_job')); 
      } 
     }, 
     do_the_job: function() { 

      this.do_action({ 
       name: _t("View name"), 
       type: "ir.actions.act_window", 
       res_model: "object", 
       domain: [], 
       views: [ 
        [false, "list"], 
        [false, "tree"] 
       ], 
       target: 'new', 
       context: {}, 
       view_type: 'list', 
       view_mode: 'list' 
      }); 
     } 
    }); 
} 

这个代码库/静态/ src目录/ XML/library_view.xml

<template xml:space="preserve"> 
    <t t-extend="ListView.buttons"> 
     <t t-jquery="button.oe_list_add" t-operation="after"> 
      <button t-if="widget.dataset.model == 'inventory'" class="oe_button oe_my_button oe_highlight" type="button">My Button</button> 
     </t> 
    </t> 
</template> 

在我openerp .py

'qweb': ['static/src/xml/library_view.xml'], 
+0

有什么问题?在巡视控制台中是否有任何错误?你确定你的JS被加载? – simahawk

回答

0

那你的图书馆/ stat ic/src/js/script.js文件?

添加JS中像下面odoo后端资源模板文件: -

<template id="assets_backend" name="work_group assets" inherit_id="web.assets_backend"> 
    <xpath expr="." position="inside"> 
     <script 
      type="text/javascript" 
      src="/library/static/src/js/script.js"> 
     </script> 

    </xpath> 
</template>