From 86d1884e4a7873eaf6e3e9333d26fbc2c8b7991b Mon Sep 17 00:00:00 2001 From: Sanket Brahmbhatt Date: Fri, 18 Aug 2023 11:17:43 +0530 Subject: [PATCH] [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) --- addons/website_sale/controllers/main.py | 2 ++ addons/website_sale/i18n/website_sale.pot | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 2de1d3732b7..44e34157c0d 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -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 diff --git a/addons/website_sale/i18n/website_sale.pot b/addons/website_sale/i18n/website_sale.pot index 5732ff4cc4c..2330e53bc78 100644 --- a/addons/website_sale/i18n/website_sale.pot +++ b/addons/website_sale/i18n/website_sale.pot @@ -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