콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

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 });
아바타
취소
관련 게시물 답글 화면 활동
3
6월 25
5786
1
12월 24
1926
4
3월 24
14867
0
4월 23
1837
4
3월 22
17554