Enable Dark Mode!
how-to-add-a-new-namespace-to-command-palette-in-odoo-17.jpg
By: Ramees Jaman KT

How to Add a New Namespace to Command Palette in Odoo 17

Odoo 17

In Odoo, the Command Palette is a versatile feature that allows users to quickly access and execute various tasks within the system. It offers a search capability to locate and trigger menu options, perform actions, and adjust settings. This tool leverages commands to efficiently carry out the desired operations.

How to Add a New Namespace to Command Palette in Odoo 17-cybrosys

In this article, we will delve into the process of adding new commands to the command register.

As an example, suppose we want to integrate the "!" command into the command palette. Pressing the exclamation mark on the keyboard would trigger the display of a visually appealing command palette template.

We must register a new command type to accomplish this.

1: Register a new command and define a template for rendering when the exclamation mark is clicked.

/** @odoo-module **/
import { _lt } from "@web/core/l10n/translation";
import { registry } from "@web/core/registry";
import { Component } from "@odoo/owl";
//Creates a class for rendering the template when the commander is entered
class ModelItemCommand extends Component {}
ModelItemCommand.template = "text_commander2.ModelItemsCommand";
//Creating a new namespace
const commandSetupRegistry = registry.category("command_setup");
commandSetupRegistry.add("!", {
   debounceDelay: 200,
   emptyMessage: _lt("Commands: "),
   name: _lt("Record"),
   placeholder: _lt("Search for a record..."),
});
const commandProviderRegistry = registry.category("command_provider");
commandProviderRegistry.add("model",{
   namespace: "!",
   async provide(env, options){
       const suggestion = []
       suggestion.push({
           Component: ModelItemCommand,
       });
       return suggestion
   },
});

class ModelItemCommand extends Component {}

ModelItemCommand.template = "text_commander2.ModelItemsCommand";

In the code mentioned, a `ModelItemCommand` component is created, which extends from the main component and defines its own template. This way, when the exclamation mark is pressed, the system will display the `ModelItemCommand` using the designated template.

commandSetupRegistry.add("!", {

debounceDelay: 200,

emptyMessage: _lt("Commands: "),

name: _lt("Record"),

placeholder: _lt("Search for a record..."),

});

In the given code, we are registering the "!" key as a command. Additionally, you can define placeholders and customize the messages that appear when no results are found.

commandProviderRegistry.add("model",{

namespace: "!",

async provide(env, options){

    const suggestion = []

    suggestion.push({

        Component: ModelItemCommand,

    });

    return suggestion

}

Here you can see “commandProviderRegistry” component is set to namespace “!”,

2: Here is an example of Xml template file

<?xml version="1.0" encoding="utf-8"?>
<template>
   <t t-name="text_commander2.ModelItemsCommand" owl="1">
       <div style="margin-left:25px;padding:10px;">
           <span>Template</span>
       </div>
   </t>
</template>

3: Result

How to Add a New Namespace to Command Palette in Odoo 17-cybrosys

As demonstrated in the previous code, the exclamation mark command triggers the template body. Additionally, the instructions are displayed below the template body for further guidance.

To read more about How to Add a New Namespace to Command Palette in Odoo 16?, refer to our blog How to Add a New Namespace to Command Palette in Odoo 16.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message