İçereği Atla
Menü
Bu soru işaretlendi
1026 Görünümler

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
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
3
Haz 25
6109
2
Eyl 25
2374
4
Mar 24
15235
0
Nis 23
2024
4
Mar 22
17734