From 0e2a431fc96691ec1a5cee87608832a78d4b87b2 Mon Sep 17 00:00:00 2001 From: "Mahdi Cheikh Rouhou (macr)" Date: Mon, 14 Aug 2023 08:21:01 +0000 Subject: [PATCH] [FIX] sale_product_configurator: edit product with variants sale line Issue: ====== When you edit an already saved product line which has variants it will throw an error. Steps to reproduce the error: ============================= 1-create 2 products having at least one variant each and make them storable 2-create a sale order and add only the first product and save the SO 3-edit the sale line of the first product with the second product and try to save it Origin of the problem: ====================== When retrieving combination we didn't check that the variants are associated to the product. Solution: ========= Try to get the variants that are associated to the product , if there is no such variants we apply get_first_possible_combination opw-3423065 opw-3450266 closes odoo/odoo#132527 X-original-commit: 06d18005762377c5188c5537ba4d17c4efd66948 Signed-off-by: Mahdi Cheikh Rouhou (macr) --- addons/sale_product_configurator/controllers/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/sale_product_configurator/controllers/main.py b/addons/sale_product_configurator/controllers/main.py index bf1c098e481..f5d4d8ad175 100644 --- a/addons/sale_product_configurator/controllers/main.py +++ b/addons/sale_product_configurator/controllers/main.py @@ -42,9 +42,10 @@ class ProductConfiguratorController(Controller): request.update_context(allowed_company_ids=[company_id]) product_template = request.env['product.template'].browse(product_template_id) + combination = request.env['product.template.attribute.value'] if ptav_ids: - combination = request.env['product.template.attribute.value'].browse(ptav_ids) - else: + combination = request.env['product.template.attribute.value'].browse(ptav_ids).filtered(lambda ptav: ptav.product_tmpl_id.id == product_template_id) + if not combination: combination = product_template._get_first_possible_combination() return dict(