This commit is contained in:
2026-11-08 20:08:53 +08:00
parent 7526a5fe4d
commit 9b924747c5
2692 changed files with 394867 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import { useDataGetter } from "@ai/utils/bus_data_getter";
import { KnowledgeCoverDialog } from "@knowledge/components/knowledge_cover/knowledge_cover_dialog";
import { t, useProps } from "@odoo/owl";
import { patch } from "@web/core/utils/patch";
patch(KnowledgeCoverDialog.prototype, {
setup() {
super.setup();
this.aiKnowledgeProps = useProps({
coverImagePath: t.string().optional(),
});
useDataGetter("mediaDialog", () => this.getMediaDialogData());
},
getMediaDialogData() {
return {
aiSpecialActions: {
useThis: async ({ message, store }) => {
const orm = store.env.services.orm;
const imageAttachment = message.attachment_ids.filter((attachment) =>
attachment.mimetype.includes("image")
)[0];
const [coverId] = await orm.create("knowledge.cover", [
{ attachment_id: imageAttachment.id },
]);
await this.props.save(coverId);
},
},
imagePath: this.aiKnowledgeProps.coverImagePath,
mediaDialogCloseFunction: () => this.props.close(),
};
},
});

View File

@@ -0,0 +1,11 @@
import { patch } from "@web/core/utils/patch";
import { KnowledgeArticleFormController } from "@knowledge/js/knowledge_controller";
patch(KnowledgeArticleFormController.prototype, {
getKnowledgeCoverDialogProps(){
let props = super.getKnowledgeCoverDialogProps();
props['coverImagePath'] = this.model.root.data.cover_image_url;
return props;
},
})

View File

@@ -0,0 +1,23 @@
import { WysiwygArticleHelper } from "@knowledge/components/wysiwyg_article_helper/wysiwyg_article_helper";
import { patch } from "@web/core/utils/patch";
import { _t } from "@web/core/l10n/translation";
import { useService } from "@web/core/utils/hooks";
patch(WysiwygArticleHelper.prototype, {
setup(){
super.setup();
this.aiChatLauncher = useService("aiChatLauncher");
},
async onGenerateArticleClick() {
// remove the "default" h1 of the article, otherwise we'll insert into the h1
const existingTitle = this.props.editor.document.querySelector("h1");
if (existingTitle) {
existingTitle.remove();
}
await this.props.editor.shared.chatgpt.openDialog({
"callerComp": "html_field_knowledge",
"channelTitle": _t("Knowledge Article Editor"),
});
}
});

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-inherit="knowledge.WysiwygArticleHelper" t-inherit-mode="extension">
<xpath expr="//button[hasclass('o_knowledge_load_template')]" position="after">
<button class="o_knowledge_generate_article d-flex btn btn-secondary align-items-center text-nowrap" data-hotkey="G" t-on-click="this.onGenerateArticleClick">
<span class="oi-fw o_ai_icon_color me-2" data-icon="o_ai_icon"/> Write with AI
</button>
</xpath>
</t>
</templates>

View File

@@ -0,0 +1,58 @@
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { deliverAIResults, setupAIResults } from "@ai/../tests/tours/ai_tour_helpers";
import { stepUtils } from "@web_tour/tour_utils";
registry.category("web_tour.tours").add("replace_knowledge_cover_with_ai_tour", {
steps: () => [
{
content: "Open Knowledge App",
trigger: '.o_app[data-menu-xmlid="knowledge.knowledge_menu_root"]',
run: "click",
},
{
content: "Open Articles Menu",
trigger: '.o_nav_entry[data-menu-xmlid="knowledge.knowledge_menu_article"]',
run: "click",
},
{
content: "Select the article 'Article with Cover'",
trigger: ".o_data_cell:text(Article with Cover)",
run: "click",
},
{
content: "Hover over the Knowledge cover and click on Replace cover button",
trigger: ".o_knowledge_cover",
run: "hover && click .o_knowledge_option_button i[title='Change cover']",
},
{
content: "Wait for Media Dialog to open and click on the AI button",
trigger: ".o_select_media_dialog button[title='Generate Image with AI']",
run: "click",
},
setupAIResults(),
{
content:
"Click on the prompt button 'Help me generate an image' in the AI chat channel",
trigger: ".ai-chat-prompt-button:contains('Help me generate an image')",
run: "click",
},
{
content: "Verify the message 'Help me generate an image' is posted in the chat channel",
trigger: ".o-mail-Message:contains('Help me generate an image')",
},
deliverAIResults(),
{
content: "Hover over the first AI generated image",
trigger: ".o-mail-Message:contains('AI Generated 1') .o-mail-AttachmentList img",
run: "hover",
},
{
content: "Verify that 'Use This' button is visible and click on it",
trigger: "button[name='media_dialog_use_this']:visible",
run: "click",
},
...stepUtils.saveForm(),
],
});