如何在树视图上添加按钮下一个打印按钮?

时间:2017-07-26 11:12:15

标签: odoo-10

我可以在表单上添加按钮,但我想知道如何在树形视图上的打印或创建按钮旁边添加按钮。有可能吗?

enter image description here

1 个答案:

答案 0 :(得分:1)

在Odoo 10.我的代码添加一个下拉列表:

你可以这样做: static / 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>

感谢。