Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
691 มุมมอง

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 });
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
มิ.ย. 25
5588
1
ธ.ค. 24
1711
4
มี.ค. 24
14692
0
เม.ย. 23
1746
Creating a new view TYPE from scratch. แก้ไขแล้ว
4
มี.ค. 22
17438