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,13 @@
import { patch } from "@web/core/utils/patch";
import { ProductImageFieldWithMediaDialog } from "@ai_product/modules/html_editor/fields/product_image_field_with_media_dialog";
import { product_extra_image_action } from "@ai_website_sale/modules/web/product_ai_actions";
patch(ProductImageFieldWithMediaDialog.prototype, {
get aiSpecialActions() {
const actions = super.aiSpecialActions;
if (["product.template", "product.product"].includes(this.props.record._config.resModel)) {
actions.product_extra_image = product_extra_image_action();
}
return actions;
},
});

View File

@@ -0,0 +1,13 @@
import { patch } from "@web/core/utils/patch";
import { ProductX2ManyMediaViewer } from "@ai_product/modules/html_editor/fields/product_x2many_media_viewer";
import { product_extra_image_action } from "@ai_website_sale/modules/web/product_ai_actions";
patch(ProductX2ManyMediaViewer.prototype, {
get aiSpecialActions(){
const actions = super.aiSpecialActions;
if (["product.template", "product.product"].includes(this.props.record._config.resModel)) {
actions.product_extra_image = product_extra_image_action();
}
return actions;
}
})

View File

@@ -0,0 +1,25 @@
import { MediaDialog } from "@html_editor/main/media/media_dialog/media_dialog";
import { t, useProps } from "@odoo/owl";
import { patch } from "@web/core/utils/patch";
patch(MediaDialog.prototype, {
setup() {
super.setup();
this.aiWebsiteSaleProps = useProps({
fromShopExtraImage: t.boolean().optional(),
reloadEditorAfterSave: t.boolean().optional(),
});
},
async aiSaveAction() {
await super.aiSaveAction(...arguments);
if (this.aiWebsiteSaleProps.reloadEditorAfterSave) {
this.env.bus.trigger("RELOAD_EDITOR");
}
},
getMediaDialogData() {
return Object.assign(super.getMediaDialogData(), {
fromShopExtraImage: this.aiWebsiteSaleProps.fromShopExtraImage,
});
},
});

View File

@@ -0,0 +1,16 @@
import { _t } from "@web/core/l10n/translation";
import { registerMessageAction } from "@mail/core/common/message_actions";
import { AIMessageActions } from "@ai/discuss/message_actions_patch";
AIMessageActions.push('product_extra_image');
registerMessageAction('product_extra_image', {
condition: ({ message, channel }) => {
return !!channel?.aiSpecialActions?.product_extra_image
&& !message.isSelfAuthored
&& !!message.attachment_ids.filter(attachment => attachment.mimetype.includes('image')).length
},
name: _t("Extra Photo"),
onSelected: ({ channel, ...args }) => channel.aiSpecialActions.product_extra_image({ channel, ...args }),
sequence: 10,
});

View File

@@ -0,0 +1,13 @@
import { patch } from "@web/core/utils/patch";
import { FormController } from "@web/views/form/form_controller";
import { product_extra_image_action } from "@ai_website_sale/modules/web/product_ai_actions";
patch(FormController.prototype, {
get aiSpecialActions() {
const actions = super.aiSpecialActions;
if (["product.template", "product.product"].includes(this.model.root.config.resModel)) {
actions.product_extra_image = product_extra_image_action();
}
return actions;
},
});

View File

@@ -0,0 +1,13 @@
import { saveMultipleAttachments } from "@web/core/utils/image_library";
export function product_extra_image_action(){
return async ({ channel, message, store }) => {
const imageAttachment = message.attachment_ids.filter(attachment => attachment.mimetype.includes('image'))[0];
await saveMultipleAttachments(store.env, {
attachments: [imageAttachment],
targetRecord: channel.targetRecord,
targetFieldName: "product_template_image_ids",
convertToWebp: true,
});
}
}

View File

@@ -0,0 +1,40 @@
import { _t } from "@web/core/l10n/translation";
import { patch } from "@web/core/utils/patch";
import { WebsiteBuilder } from "@website/builder/website_builder";
patch(WebsiteBuilder.prototype, {
async onAiChatClick() {
const mainObject = this.websiteService.currentWebsite?.metadata?.mainObject;
if (mainObject?.model !== "product.template" || !mainObject.id) {
return super.onAiChatClick();
}
const orm = this.env.services.orm;
const variantId = parseInt(
this.websiteService.pageDocument
?.querySelector('.js_product button[name="add_to_cart"]')
?.dataset.productId,
10,
);
const [recordModel, recordId] = variantId
? ["product.product", variantId]
: ["product.template", mainObject.id];
const applyImage = (model, id, method) => async ({ message }) => {
const attachment = message.attachment_ids.find((a) => a.mimetype.includes("image"));
await orm.call(model, method, [[id], attachment.id]);
await this.editor.config.reloadEditor();
};
await this.env.services.aiChatLauncher.launchAIChat({
interfaceKey: "chatter_ai_button",
channelTitle: _t("AI Website Product Edit"),
recordModel,
recordId,
aiSpecialActions: {
product_main_image: applyImage(recordModel, recordId, "ai_set_main_image"),
product_extra_image: applyImage("product.template", mainObject.id, "ai_add_extra_image"),
},
});
},
});

View File

@@ -0,0 +1,24 @@
import { patch } from "@web/core/utils/patch";
import { ProductAddImageAction } from "@website_sale/website_builder/product_variant_option_plugin";
import { TABS } from "@html_editor/main/media/media_dialog/media_dialog_utils";
patch(ProductAddImageAction.prototype, {
getMediaDialogProps({ editingElement, loadPromiseResolveFunction }) {
const props = super.getMediaDialogProps({ editingElement, loadPromiseResolveFunction });
const { model, productProductID: productID, productTemplateID: templateID } = this;
const resID = parseInt(model === "product.product" ? productID : templateID);
return {
...props,
reloadEditorAfterSave: true,
originalRecordModel: model,
originalRecordId: resID,
fromShopExtraImage: true,
aiSave: async (imgEl, selectedMedia, activeTab) => {
if (selectedMedia.length > 0) {
const type = activeTab === TABS["IMAGES"].id ? "image" : "video";
await this.apply({ editingElement, loadResult: { imgEls: [imgEl], selectedMedia, type } })
}
},
};
},
});