创建客户端操作

客户端操作会触发一个完全在客户端实现的操作。使用客户端操作的好处之一是可以轻松创建高度定制化的界面。客户端操作通常由一个 OWL 组件定义;我们还可以使用 Web 框架以及服务、核心组件、钩子等。

  1. 创建 客户端操作 ,别忘了使其可访问。

    <record model="ir.actions.client" id="my_client_action">
        <field name="name">My Client Action</field>
        <field name="tag">my_module.MyClientAction</field>
    </record>
    
  2. 创建一个代表客户端操作的组件。

    my_client_action.js
    import { registry } from "@web/core/registry";
    
    import { Component } from  "@odoo/owl";
    
    class MyClientAction extends Component {
        static template = "my_module.clientaction";
    }
    
    // remember the tag name we put in the first step
    registry.category("actions").add("my_module.MyClientAction", MyClientAction);
    
    my_client_action.xml
    <?xml version="1.0" encoding="UTF-8" ?>
    <templates xml:space="preserve">
        <t t-name="awesome_tshirt.clientaction">
            Hello world
        </t>
    </templates>