2017-07-26 91 views
1

我可以在窗體上添加按鈕,但我想知道如何在樹視圖上添加一個按鈕來打印或創建按鈕。可能嗎?如何在樹形視圖中添加按鈕下一個打印按鈕?

enter image description here

+0

意味着你想在樹形視圖中添加按鈕?請指定放置按鈕上的哪個地方給屏幕截圖... –

+0

我添加了屏幕截圖 – Borealis

+0

這是可能的。但你麻煩編輯JavaScript代碼。這很醜陋。你應該在每一行樹上添加一個按鈕,或者在一個動作unter Action中添加一個按鈕。 – qvpham

回答

0

在Odoo 10.我的代碼中添加一個下拉列表:

你可以這樣做:靜態/ XML/my_btn_temp.xml

<?xml version="1.0" encoding="utf-8" ?> 
<templates id="template" xml:space="preserve"> 
    <t t-extend="ListView.buttons"> 
    <t t-jquery="button.o_list_button_discard" t-operation="after"> 
     <t t-if="widget.model=='product.template'"> 
      <select class="oe_my_priceliste_button btn btn-sm btn-primary" name="oe_my_priceliste_button" id="oe_my_priceliste_button" 
      style="margin-left:7%;width:45%;display:inline-block;border: 1px solid #CCCCCC; border-radius: 3px; background: orange;color:white;"> 
      </select> 
     </t> 
    </t> 
    </t> 
</templates> 

並添加此qweb到__manifest__.py

'data': [....], 
'qweb': ['static/xml/my_btn_temp.xml',], 

而且將動作添加到該按鈕,你可以用JS做到這一點:

odoo.define('my_module.btn_price_list_tree', function(require) { 
"use strict"; 

var core = require('web.core'); 
var utils = require('web.utils'); 
var Model = require('web.Model'); 
var Widget = require('web.Widget'); 
var ViewManager = require('web.ViewManager'); 
var ControlPanel = require('web.ControlPanel'); 
var ListView = require('web.ListView'); 
var dataset = require('web.data'); 
var Dialog = require('web.Dialog'); 
var list_widget_registry = core.list_widget_registry; 

var QWeb = core.qweb; 
var _t = core._t; 

ListView.include({ 

    load_list: function(data) { 
     var self = this; 
     var result = this._super.apply(this, arguments); 
     var CHOICE = _t("Choose a price list"); 
     var op_tions = "<option value='-1'>"+CHOICE+"</option>"; 
     if (this.$el) { 
      new Model("product.pricelist").query().all().then(function(ret){ 
       if(ret){ 
        for(var ind=0; ind< ret.length; ind++){ 
         var res = ret[ind]; 
         op_tions += "<option value='"+res.id+"'>"+res.name+"</option>"; 
        } 
        $('#oe_my_priceliste_button').html(op_tions); 
       } 
      }); 
     } 
     return result; 
    }, 

    render_buttons: function() { 
     var self = this; 
     var add_button = false; 
     if (!this.$buttons) { // Ensures that this is only done once 
      add_button = true; 
     } 
     this._super.apply(this, arguments); // Sets this.$buttons 
     if(add_button) { 
      this.$buttons.on('change', '.oe_my_priceliste_button', this.proxy('do_price_list_dropdown_change')); 
     } 
    }, 

    do_price_list_dropdown_change: function(){ 
     var price_list_id = $('#oe_my_priceliste_button').val(); 
     new Model("product.template").call("do_price_list_dropdown_change",[[],price_list_id], {}, {async: true}).done(function(data) { 
      window.location.reload(true); 
     }); 
    }, 
    }); 

}); 

而且你添加的JS: /views/assets.js

<?xml version="1.0" encoding="utf-8"?> 
<odoo> 
    <data> 
     <template id="assets_backend" name="project assets" inherit_id="web.assets_backend"> 
     <xpath expr="." position="inside"> 
      <script type="text/javascript" src="/plw_core/static/src/js/add_pricelist_dropdown.js"></script> 
     </xpath> 
     </template> 
    </data> 
</odoo> 

感謝。

相關問題