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,8 @@
import { ComposerAction } from "@mail/core/common/composer_actions";
import { patch } from "@web/core/utils/patch";
patch(ComposerAction.prototype, {
_getAiComposerActions() {
return [...super._getAiComposerActions(), "add-documents"];
},
});

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="ai.AIDocumentsFileViewer" t-inherit="documents.FileViewer" t-inherit-mode="extension">
<xpath expr="//div[hasclass('o-FileViewer-header')]//div[hasclass('flex-grow-1')]" position="after">
<t t-if="!this.env.searchModel.context.documents_view_secondary" t-call="ai.AIFileButton"/>
</xpath>
</t>
</templates>

View File

@@ -0,0 +1,57 @@
import {
SelectAddDocumentCreateDialog,
selectAddDocumentCreateDialogProps,
} from "@documents/views/view_dialogs/select_add_document_create_dialog";
import { Domain } from "@web/core/domain";
import { patch } from "@web/core/utils/patch";
import { t } from "@odoo/owl";
Object.assign(selectAddDocumentCreateDialogProps, {
addFromDocuments: t.function().optional(),
});
patch(SelectAddDocumentCreateDialog.prototype, {
get viewProps() {
const viewProps = super.viewProps;
const thread = this.props.chatterParams?.thread || this.props.thread;
if (thread?.channel?.isAiChat) {
// indexable files and image types supported by most AI providers
viewProps.domain = Domain.and([
viewProps.domain,
Domain.or([
[
[
"file_extension",
"in",
[
"docx",
"pptx",
"xlsx",
"odt",
"ods",
"odp",
"png",
"jpg",
"jpeg",
"webp",
"gif",
],
],
],
[["mimetype", "=", "application/pdf"]],
[["mimetype", "=like", "text/%"]],
]),
]).toList();
}
return viewProps;
},
get addDocumentsAttachmentMethod() {
return this.props.chatterParams?.addDocumentsAttachment || this.props.addFromDocuments || this.addDocumentsAttachment;
},
get showPasteDocumentsLink() {
const thread = this.props.chatterParams?.thread || this.props.thread;
return !thread?.channel?.isAiChat && !this.props.addFromDocuments;
},
});

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="ai_documents_source.SelectAddDocumentCreateDialog"
t-inherit="documents.SelectAddDocumentCreateDialog"
t-inherit-mode="extension">
<xpath expr="//button[@name='addLinks']" position="attributes">
<attribute name="t-if">this.showPasteDocumentsLink</attribute>
</xpath>
</t>
</templates>

View File

@@ -0,0 +1,34 @@
import {
contains,
click,
setupChatHub,
start,
startServer,
} from "@mail/../tests/mail_test_helpers";
import { describe, test } from "@odoo/hoot";
import {
defineModels,
} from "@web/../tests/web_test_helpers";
import { DocumentsModels } from "@documents/../tests/helpers/data";
import { basicDocumentsKanbanArch } from "@documents/../tests/helpers/views/kanban";
import { getEnrichedSearchArch } from "@documents/../tests/helpers/views/search";
describe.current.tags("desktop");
DocumentsModels.DocumentsDocument._views = {
kanban: basicDocumentsKanbanArch,
[["search", false]]: getEnrichedSearchArch(),
};
defineModels(DocumentsModels);
test("Can 'Add from Documents' in chat window", async () => {
// This might conflict with focusing next chat window
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({ name: "General" });
setupChatHub({ opened: [channelId] });
await start();
await click(".o-mail-ChatWindow button[title='More Actions']");
await click(".dropdown-item:has(:text('Add from Documents'))");
await contains(".modal-title:text('Search: Documents')");
});