Se rendre au contenu
Menu
Cette question a été signalée

Hi, in Odoo 17 I'm trying to add an option in the cogmenu actions that is visible only in some specific views.

The js code below is successfully making the option appear in the cog menu, but the isDisplayed property applies to every view. With the config property I can get the viewId of the current view, but I don't want to rely on view id numbers (as I understand this can change between odoo installations).

Is there a way to get the ids of some specific views and verify if any of them matches with the config.viewId property?


/** @odoo-module **/
import { DropdownItem } from "@web/core/dropdown/dropdown_item";
import { registry } from "@web/core/registry";
import { useService } from "@web/core/utils/hooks";
const { Component } = owl;
const cogMenuRegistry = registry.category("cogMenu");

export class CogMenu extends Component {
setup() {
this.actionService = useService("action");
}

async myAction() {
try {
this.actionService.doAction({
name: "My action",
type: 'ir.actions.act_window',
res_model: 'my.action.wizard',
view_mode: 'form',
views: [[false, 'form']],
target: 'new',
});
} catch (error) {
console.error("Error opening wizard:", error);
}
}
}
CogMenu.template = "blog_cog_menu.MyAction";
CogMenu.components = { DropdownItem };

export const CogMenuItem = {
Component: CogMenu,
groupNumber: 20,
isDisplayed: ({ config }) => {
console.log(config.viewId);
// Check if viewId is the id of product.template.view view
return true;
},
};

cogMenuRegistry.add("my-action", CogMenuItem, { sequence: 10 });
Avatar
Ignorer
Publications associées Réponses Vues Activité
3
juin 25
5575
1
déc. 24
1694
4
mars 24
14668
0
avr. 23
1741
4
mars 22
17430