[FIX] website_sale_comparison: Fix category order

Use category sequence to order them instead of their order of appearance in
the list of sequence ordered attributes

closes odoo/odoo#35610

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
Patrick Tombez
2019-08-13 11:31:10 +00:00
parent 119ca24d60
commit a2b98e94be
2 changed files with 7 additions and 6 deletions
@@ -18,14 +18,15 @@ class WebsiteSaleProductComparison(WebsiteSale):
products = request.env['product.product'].search([('id', 'in', product_ids)])
values['products'] = products.with_context(display_default_code=False)
res = {}
res = OrderedDict()
attrs = products.mapped('attribute_line_ids.attribute_id').filtered(lambda x: x.create_variant)
for attr in attrs.sorted(lambda att: (att.category_id.sequence, att.sequence)):
cat_name = attr.category_id.name or _('Uncategorized')
res.setdefault(cat_name, OrderedDict()).setdefault(attr.name, [' - '] * len(products))
for num, product in enumerate(products):
for var in product.attribute_line_ids.sorted(lambda x: x.attribute_id.sequence):
for var in product.attribute_line_ids.filtered(lambda x: x.attribute_id.create_variant):
cat_name = var.attribute_id.category_id.name or _('Uncategorized')
att_name = var.attribute_id.name
if not var.attribute_id.create_variant:
continue
res.setdefault(cat_name, OrderedDict()).setdefault(att_name, [' - '] * len(products))
val = product.attribute_value_ids.filtered(lambda x: x.attribute_id == var.attribute_id)
res[cat_name][att_name][num] = val[0].name
values['specs'] = res
@@ -26,6 +26,6 @@ class ProductTemplate(models.Model):
def get_variant_groups(self):
res = OrderedDict()
for var in self.attribute_line_ids.sorted(lambda x: x.attribute_id.sequence):
for var in self.attribute_line_ids.sorted(lambda x: (x.attribute_id.category_id.sequence, x.attribute_id.sequence)):
res.setdefault(var.attribute_id.category_id.name or _('Uncategorized'), []).append(var)
return res