[FIX] website_sale: stop user while video swap at first position in web editor

When the customer tries to move the video to the first position of the product
image. at that time, the error would be generated.

step to reproduce:
-Install the website_sale
-open Invoicing > vendors > Products > open any Product
-open sales Notepage
-click on add a Media
-past any video url > save it
-click on Go To website from the state button
-click on Edit button > again double click on the image
-then click on a right side position of re-order

error- Key Error:'video_url'

After applying our commit, if the customer got a validation error when
the customer attempted to swap the video into the product images at
 the first position. There is a controller named
`/shop/product/resequence-image` which called, when the customer
changes the position of the video.

https://github.com/odoo/odoo/blob/3ce90ddf33f59a80de34cbafd05679d0817d0076/addons/website_sale/controllers/main.py#L582-L587

The `image res_model` will then receive the `product.image` model when a
customer moves a video from the third to the second position, and that model
locates the field known as `video_url`. However, when a customer moves a
video from the second to the first position, `image res_model` will then
receive the `product.product`  model, and that model finds the same field but
does not have that field in it.

sentry-4393257638

closes odoo/odoo#133878

X-original-commit: 8a6a5a10befb98bfe21e5beaf60c9a303304486a
Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
This commit is contained in:
Sanket Brahmbhatt
2023-09-01 11:39:58 +00:00
parent 498d438f3d
commit 86d1884e4a
2 changed files with 9 additions and 0 deletions
+2
View File
@@ -595,6 +595,8 @@ class WebsiteSale(http.Controller):
other_image = product_images[new_image_idx]
source_field = hasattr(image_to_resequence, 'video_url') and image_to_resequence.video_url and 'video_url' or 'image_1920'
target_field = hasattr(other_image, 'video_url') and other_image.video_url and 'video_url' or 'image_1920'
if target_field == 'video_url' and image_res_model == 'product.product':
raise ValidationError(_("Can not resequence a video at first position."))
previous_data = other_image[target_field]
other_image[source_field] = image_to_resequence[source_field]
image_to_resequence[target_field] = previous_data
@@ -996,6 +996,13 @@ msgstr ""
msgid "Can Publish"
msgstr ""
#. module: website_sale
#. odoo-python
#: code:addons/website_sale/controllers/main.py:0
#, python-format
msgid "Can not resequence a video at first position."
msgstr ""
#. module: website_sale
#. odoo-python
#: code:addons/website_sale/controllers/main.py:0