Skip to content
Permalink
Browse files

[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 #35610

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
  • Loading branch information...
p-tombez committed Aug 9, 2019
1 parent 119ca24 commit a2b98e94beb2b64623bfca006e96d34cb6651ae8
@@ -18,14 +18,15 @@ def product_compare(self, **post):
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

0 comments on commit a2b98e9

Please sign in to comment.
You can’t perform that action at this time.