From cbdbcada133596ee3feacc26cc060d6fe928602a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Thu, 2 Jul 2026 11:16:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_ai_agent/static/src/js/ai_rule_test.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 yuthon_ai_agent/static/src/js/ai_rule_test.js diff --git a/yuthon_ai_agent/static/src/js/ai_rule_test.js b/yuthon_ai_agent/static/src/js/ai_rule_test.js new file mode 100644 index 000000000..04e4e890e --- /dev/null +++ b/yuthon_ai_agent/static/src/js/ai_rule_test.js @@ -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 会重新渲染) + } +}; From dc3d54d353dfed6ca9563393f1667e3ff08c27a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Thu, 2 Jul 2026 11:16:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_ai_agent/security/ai_security.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yuthon_ai_agent/security/ai_security.xml b/yuthon_ai_agent/security/ai_security.xml index e40d83d2b..634b5a2fc 100644 --- a/yuthon_ai_agent/security/ai_security.xml +++ b/yuthon_ai_agent/security/ai_security.xml @@ -3,7 +3,7 @@ AI Agent 用户 - + 使用 AI 对话功能 @@ -11,7 +11,7 @@ AI Agent 管理员 - + 管理 AI 服务商配置