Tạo một client action

Một client action kích hoạt một action được triển khai hoàn toàn ở phía client. Một trong những lợi ích của việc sử dụng client action là khả năng dễ dàng tạo ra các giao diện được tùy chỉnh sâu. Một client action thường được định nghĩa bởi một component OWL; chúng ta cũng có thể sử dụng web framework cùng với các service, core component, hook,...

  1. Tạo client action, đừng quên làm cho nó có thể truy cập được.

    <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. Tạo một component đại diện cho client action.

    my_client_action.js
    /** @odoo-module **/
    
    import { registry } from "@web/core/registry";
    
    import { Component } from  "@odoo/owl";
    
    class MyClientAction extends Component {}
    MyClientAction.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>