From 26f447a072abd76ac7bab28e93d6d6e6e4539f01 Mon Sep 17 00:00:00 2001 From: Rodolpho Lima Date: Thu, 7 Sep 2023 14:25:34 +0200 Subject: [PATCH] [FIX] web_editor: missing record info for converted images When the Wysiwyg is used by website, multiple editable elements are possible, and each of them carry the related record's model and id in the element's dataset. On the other hand, when the Wysiwyg is used by the html field, there's only one root editable element, and such information is not present in the editable's dataset, but in the widget's options object. Before this commit, when saving the content of an html field, modified images were converted to attachments without the correct reference to the record's model and id. This commit makes sure that such information is passed to the route that handles attachment creation. task-3495668 closes odoo/odoo#135806 Signed-off-by: David Monjoie (dmo) Signed-off-by: Antoine Guenet (age) --- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 5 ++++- addons/web_editor/static/tests/html_field_tests.js | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 35dbebac724..25ef94d3ee9 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1159,7 +1159,10 @@ export class Wysiwyg extends Component { */ savePendingImages($editable = this.$editable) { const defs = Array.from($editable).map(async (editableEl) => { - const {res_model: resModel, res_id: resId} = this.options.recordInfo; + let { oeModel: resModel, oeId: resId } = editableEl.dataset; + if (!resModel) { + ({ res_model: resModel, res_id: resId } = this.options.recordInfo); + } // When saving a webp, o_b64_image_to_save is turned into // o_modified_image_to_save by _saveB64Image to request the saving // of the pre-converted webp resizes and all the equivalent jpgs. diff --git a/addons/web_editor/static/tests/html_field_tests.js b/addons/web_editor/static/tests/html_field_tests.js index 8097edc83b3..1c435383ab6 100644 --- a/addons/web_editor/static/tests/html_field_tests.js +++ b/addons/web_editor/static/tests/html_field_tests.js @@ -293,7 +293,7 @@ QUnit.module("WebEditor.HtmlField", ({ beforeEach }) => { QUnit.module('Save scenarios'); QUnit.test("Ensure that urgentSave works even with modified image to save", async (assert) => { - assert.expect(3); + assert.expect(5); let formController; // Patch to get the controller instance. patchWithCleanup(FormController.prototype, { @@ -377,6 +377,8 @@ QUnit.module("WebEditor.HtmlField", ({ beforeEach }) => { route === `/web_editor/modify_image/${imageRecord.id}` ) { if (modifyImageCount === 0) { + assert.equal(args.res_model, 'partner'); + assert.equal(args.res_id, 1); await modifyImagePromise; return newImageSrc; } else { @@ -437,7 +439,7 @@ QUnit.module("WebEditor.HtmlField", ({ beforeEach }) => { }); QUnit.test("Pasted/dropped images are converted to attachments on save", async (assert) => { - assert.expect(4); + assert.expect(6); // Patch to get a promise to get the htmlField component instance when // the wysiwyg is instancied. @@ -457,6 +459,9 @@ QUnit.module("WebEditor.HtmlField", ({ beforeEach }) => { const mockRPC = async function (route, args) { if (route === '/web_editor/attachment/add_data') { + // Check that the correct record model and id were sent. + assert.equal(args.res_model, 'partner'); + assert.equal(args.res_id, 1); return { image_src: '/test_image_url.png', access_token: '1234',