odoo tree视图添加自定义按钮

odoo tree视图添加自定义按钮

  • 编写js
  • xml导入js
  • 写xml模板添加按钮
  • tree视图添加class

编写js

odoo.define('marketing_management.bond_manager_button_create', function (require) {

    "use strict";

    var ListController = require('web.ListController');

    ListController.include({

        renderButtons: function ($node) {

            this._super.apply(this, arguments);

            if (this.$buttons) {

                this.$buttons.find('.create_imitate_button').on('click', this.proxy('create_imitate_function'));

            }

        },

        create_imitate_function: function () {
            let self = this
            console.log('创建按钮被点击')
        },

    });

});

xml导入js


<odoo>
    <template id="assets_backend" name="tree view menu" inherit_id="web.assets_backend">
        <xpath expr="." position="inside">
            <script type="text/javascript" src="/marketing_management/static/src/js/bond_manager_botton.js">script>
        xpath>
    template>
odoo>

写xml模板添加按钮


<template id="create_imitate" xml:space="preserve">
    <t t-extend="ListView.buttons">
        <t t-jquery=".o_list_buttons" t-operation="append">
            <t t-if="widget and widget.modelName == 'bond.manager'">
                <button class="btn btn-primary create_imitate_button" type="button">创建模拟button>
            t>
        t>
    t>
template>

tree视图添加class

    <record id="bond_manager_tree" model="ir.ui.view">
        <field name="name">Bond Manager Treefield>
        <field name="model">bond.managerfield>
        <field name="arch" type="xml">
            <tree class="bond_manager_button_create">
                <field name="crm_name" string='项目名称'/>
                <field name="num" string='金额'/>
                <field name="expire_date" string='到期日期'/>
                <field name="pay_date" string='支付时间'/>
                <field name="user_id" string='负责人'/>
                <field name="company_id" string='公司'/>
                <field name="state" string='状态'/>
            tree>
        field>
    record>

你可能感兴趣的:(odoo,学习,javascript,前端,开发语言)