From 97af72330a79f69352e293e0758e2a22b83720b7 Mon Sep 17 00:00:00 2001 From: Arnaud Baes Date: Mon, 20 Jan 2020 14:10:10 +0000 Subject: [PATCH] [FIX] product: Add products without 'combination_indices' to cart. Sometimes when we try to buy a product that doesn't have any variants, it would result in an error saying there isn't any valid combination for that product. This was happening because `_get_variant_id_for_combination` was considering that the field `combination_indices` would always be equal to `''` (empty string) in such a case. This isn't true as `combination_indices` isn't a required field thus allowing `null` \ `None` to be valid values for that field. This fix will simply include products with no values set for their `combination_indices` when searching a corresponding variant from the `product_template`. closes odoo/odoo#44056 X-original-commit: 03e7efc3b4592c5f063c665130011a91fcc4d683 Signed-off-by: Toufik Benjaa (tbe) --- addons/product/models/product_template.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 86bcf24abc8..8e399829112 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -6,6 +6,7 @@ import logging from odoo import api, fields, models, tools, _, SUPERUSER_ID from odoo.exceptions import ValidationError, RedirectWarning, UserError +from odoo.osv import expression _logger = logging.getLogger(__name__) @@ -894,10 +895,15 @@ class ProductTemplate(models.Model): Use sudo because the same result should be cached for all users. """ self.ensure_one() - return self.env['product.product'].sudo().with_context(active_test=False).search([ - ('product_tmpl_id', '=', self.id), - ('combination_indices', '=', filtered_combination._ids2str()) - ], order='active DESC', limit=1).id + domain = [('product_tmpl_id', '=', self.id)] + combination_indices_ids = filtered_combination._ids2str() + + if combination_indices_ids: + domain = expression.AND([domain, [('combination_indices', '=', combination_indices_ids)]]) + else: + domain = expression.AND([domain, [('combination_indices', 'in', ['', False])]]) + + return self.env['product.product'].sudo().with_context(active_test=False).search(domain, order='active DESC', limit=1).id @tools.ormcache('self.id') def _get_first_possible_variant_id(self):