stock.quant 树视图上的 Odoo 12 创建按钮

Odoo 12 Create button on Tree View on stock.quant

有什么方法可以在 stock.quant 模型上创建按钮吗?

我找到的所有解决方案都与 Create/Import 按钮有关,但 stock.quant 型号上没有它们。

到目前为止我的代码:

路径:locations_quants_report/views/templates.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
      <data>
            <template id="assets_backend" name="stock_quant_tree_view_button" 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>

路径:locations_quants_report/static/src/xml/tree_view_button.xml

<?xml version="1.0" encoding="UTF-8"?>
      <template id="template" xml:space="preserve">
          <t t-extend="ListView.buttons">
            <t t-jquery="button.o_list_button_add" t-operation="after">
                  <button t-if="widget.model == 'stock.quant'" class="btn btn-primary" type="button">Print</button>
            </t>
          </t>
      </template>

也在 __manifest__.py

上声明它们
    'data': [
        ...
        'views/template.xml'
    ],
    'qweb': [
        'static/src/xml/tree_view_button.xml',
    ],

任何解决方案我都会很棒。提前致谢!

我找到了调用我制作的用于打印线条的向导的解决方案。

路径:locations_quants_report/views/templates.xml

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

路径:locations_quants_report/static/src/xml/tree_view_button.xml

<?xml version="1.0" encoding="UTF-8"?>
      <template id="template" xml:space="preserve">
          <t t-extend="ListView.buttons">
            <t t-jquery="button.o_list_button_save" t-operation="before">
                <t t-if="widget.modelName == 'stock.quant'">
                  <button id="custom_print_btn" class="btn btn-primary o_list_button_custom_print" type="button" >Print</button> 
                </t>
            </t>
          </t>
      </template>

路径:locations_quants_report/static/src/js/tree_view_button.js

odoo.define('locations_quants_report.tree_view_button', function (require){
    "use strict";       
    var core = require('web.core');
    var ListView = require('web.ListView'); 
    var ListController = require("web.ListController");

    var includeDict = {
        renderButtons: function () {
            this._super.apply(this, arguments);
            if (this.modelName == 'stock.quant') {
                var your_btn = this.$buttons.find('button.o_list_button_custom_print');
                your_btn.on('click', this.proxy('o_list_button_custom_print'));
            }
        },
        o_list_button_custom_print: function(){
            this.do_action({
                name: "Open a wizard",
                type: 'ir.actions.act_window',
                res_model: 'locations.quants.report',
                view_mode: 'form',
                view_type: 'form',
                views: [[false, 'form']],
                target: 'new',
            });
        }
    };

    ListController.include(includeDict);
});

也在 __manifest__.py

上声明它们
    'data': [
        ...
        'views/template.xml'
    ],
    'qweb': [
        'static/src/xml/tree_view_button.xml',
    ],