Odoo16_tree视图添加按钮

1.效果图

2.按钮Qweb模板

<?xml version="1.0" encoding="utf-8"?>
<templates id="template" xml:space="preserve">

<t t-name="OwlDemoButtons" t-inherit="web.ListView.Buttons" t-inherit-mode="primary" owl="1">
    <xpath expr="(//div/*)[last()]" position="after">
        <button class="btn btn-primary" type="button" t-on-click="test">
            测试按钮
        </button>
    </xpath>
</t>

</templates>

3.js添加注册表

/** @odoo-module **/
import { registry } from "@web/core/registry";
import { listView } from "@web/views/list/list_view";
import { ListController } from "@web/views/list/list_controller";

export class OwlDemoTest extends ListController {

    setup() {
        super.setup();
    }


    test() {
        console.log("--------------");
    }

}

registry.category("views").add("owl_demo_test", {
    ...listView,
    Controller: OwlDemoTest,
    buttonTemplate: "OwlDemoButtons",
});

4.继承要添加按钮的tree页面添加js_class

<odoo>
    <data>

        <record id="owl_add_method" model="ir.ui.view">
            <field name="name">owl_add_method</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_quotation_tree_with_onboarding"/>
            <field name="arch" type="xml">
                <xpath expr="//tree" position="attributes">
                    <attribute name="js_class">owl_demo_test</attribute>
                </xpath>
            </field>
        </record>

    </data>
</odoo>

5.__manifest__.py导入js和xml

posted @ 2022-12-07 23:07  手可摘星辰。  阅读(1045)  评论(0编辑  收藏  举报