@@ -3,7 +3,7 @@
|
||||
<!-- AI Agent 用户组 -->
|
||||
<record id="group_ai_agent_user" model="res.groups">
|
||||
<field name="name">AI Agent 用户</field>
|
||||
<field name="category_id" ref="base.module_category_hidden"/>
|
||||
<field name="category_id" ref="base.module_category_administration"/>
|
||||
<field name="comment">使用 AI 对话功能</field>
|
||||
<field name="users" eval="[(4, ref('base.user_admin'))]"/>
|
||||
</record>
|
||||
@@ -11,7 +11,7 @@
|
||||
<!-- AI Agent 管理员组 -->
|
||||
<record id="group_ai_agent_admin" model="res.groups">
|
||||
<field name="name">AI Agent 管理员</field>
|
||||
<field name="category_id" ref="base.module_category_hidden"/>
|
||||
<field name="category_id" ref="base.module_category_administration"/>
|
||||
<field name="comment">管理 AI 服务商配置</field>
|
||||
<field name="implied_ids" eval="[(4, ref('yuthon_ai_agent.group_ai_agent_user'))]"/>
|
||||
<field name="users" eval="[(4, ref('base.user_admin'))]"/>
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { jsonrpc } from "@web/core/network/rpc_service";
|
||||
import { FormController } from "@web/views/form/form_controller";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
/**
|
||||
* 主动感知规则表单:测试按钮点击处理
|
||||
*
|
||||
* 拦截"测试主动感知"按钮的点击:
|
||||
* 1. 调用 /ai/rule/test_guide 创建测试消息
|
||||
* 2. 成功后派发事件通知浮动聊天框打开并刷新
|
||||
*/
|
||||
patch(FormController.prototype, "yuthon_ai_agent.ActiveGuideTest", {
|
||||
setup() {
|
||||
super.setup(...arguments);
|
||||
},
|
||||
});
|
||||
|
||||
// 注入全局函数到 window,供 onclick 调用
|
||||
window._testActiveGuide = async function (btnEl) {
|
||||
const formEl = btnEl.closest(".o_form_view");
|
||||
if (!formEl) return;
|
||||
// 从 URL 或 data 属性获取 record id
|
||||
const resId = formEl.dataset?.resId
|
||||
|| (new URLSearchParams(window.location.search)).get("id");
|
||||
if (!resId) {
|
||||
alert("无法获取规则 ID");
|
||||
return;
|
||||
}
|
||||
|
||||
btnEl.disabled = true;
|
||||
btnEl.textContent = "⏳ 测试中...";
|
||||
|
||||
try {
|
||||
const res = await jsonrpc("/ai/rule/test_guide", { rule_id: parseInt(resId) });
|
||||
if (res.error) {
|
||||
alert("错误: " + res.error);
|
||||
} else {
|
||||
// 通知浮动聊天框打开
|
||||
window.dispatchEvent(new CustomEvent("yuthon:ai_open_chat", {
|
||||
detail: { forceOpen: true },
|
||||
}));
|
||||
}
|
||||
} catch (e) {
|
||||
alert("测试失败: " + e.message);
|
||||
} finally {
|
||||
btnEl.disabled = false;
|
||||
// 恢复按钮文字(Odoo 会重新渲染)
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user