2017-02-09 59 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>