diff --git a/yuthon_ai_agent/static/src/js/ai_rule_test.js b/yuthon_ai_agent/static/src/js/ai_rule_test.js index 04e4e890e..ef76099fb 100644 --- a/yuthon_ai_agent/static/src/js/ai_rule_test.js +++ b/yuthon_ai_agent/static/src/js/ai_rule_test.js @@ -1,29 +1,17 @@ /** @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. 成功后派发事件通知浮动聊天框打开并刷新 + * 由 XML 里 onclick="window._testActiveGuide(this)" 调用 */ -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"); + + // 从 URL 获取 record id + const resId = (new URLSearchParams(window.location.search)).get("id"); if (!resId) { alert("无法获取规则 ID"); return; @@ -37,7 +25,6 @@ window._testActiveGuide = async function (btnEl) { if (res.error) { alert("错误: " + res.error); } else { - // 通知浮动聊天框打开 window.dispatchEvent(new CustomEvent("yuthon:ai_open_chat", { detail: { forceOpen: true }, })); @@ -46,6 +33,5 @@ window._testActiveGuide = async function (btnEl) { alert("测试失败: " + e.message); } finally { btnEl.disabled = false; - // 恢复按钮文字(Odoo 会重新渲染) } };