Steps to reproduce the problem:
- Go on the "Courses" application and select a course.
- Edit.
- Replace the main image of the course with one of your own.
- Save.
-> The function route `/web_editor/modify_image/` is called two times
leading to the creation of two attachments instead of one.
The `savePendingImages()` function iterates through editable elements
and calls `/web_editor/modify_image/` (through `_saveModifiedImage()`)
for each image with a `o_modified_image_to_save` class inside those
elements. In our case, the image has an editable element parent that has
itself an editable element parent. Because since [1], the
`o_modified_image_to_save` class is removed after the `rpc` call, this
class is not removed while the `savePendingImages()` loops on the
second editable element parent of the image. As a result,
`/web_editor/modify_image/` is called two times. Note that before [1],
the process was partially wrong as well. `/web_editor/modify_image/` was
indeed called only once but with the wrong arguments. This is now fixed
by ensuring that `_saveModifiedImage()` is called with the arguments
coming from the closest editable element. The same logic is applied for
the call of the `_saveB64Image()` function.
[1]: https://github.com/odoo/odoo/commit/8872aab2d108ff3e2ec06ca4579479898c87738c
task-3451349
closesodoo/odoo#134189
X-original-commit: 8ff0151cf06c37e8ee2e344bc96c063b4921ce43
Signed-off-by: Robin Lejeune (role) <role@odoo.com>