Skip to content

Commit

Permalink
[FIX] product_attribute_variant_rules: Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Oct 25, 2023
1 parent 4b8f3cc commit 6939f21
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
18 changes: 4 additions & 14 deletions product_attribute_variant_rules/models/product_attribute_rule.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Florian Mounier <[email protected]>
from collections import defaultdict

from odoo import api, fields, models
from odoo.tools import groupby


class ProductAttributeRule(models.Model):
Expand Down Expand Up @@ -126,9 +126,9 @@ def _combination_matches_conditions(self, combination, conditions):

# Check if the combination matches the preconditions ANDed between
# different attributes
for attribute, attribute_values in self._aggregate_conditions(
conditions
).items():
for attribute, attribute_values in groupby(
conditions, lambda condition: condition.attribute_id
):
if (
combination.filtered(
lambda value: value.attribute_id == attribute
Expand All @@ -140,13 +140,3 @@ def _combination_matches_conditions(self, combination, conditions):

# The combination matches all preconditions
return True

def _aggregate_conditions(self, conditions):
"""
Group the attribute values by attribute.
"""
aggregated_conditions = defaultdict(set)
for condition in conditions:
aggregated_conditions[condition.attribute_id].add(condition)

return aggregated_conditions
2 changes: 1 addition & 1 deletion product_attribute_variant_rules/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _is_combination_possible_with_rules(self, combination):
return True

def write(self, vals):
res = super(ProductTemplate, self).write(vals)
res = super().write(vals)

# Recreate variants if the rules have changed
empty = vals.get("active") and len(self.product_variant_ids) == 0
Expand Down

0 comments on commit 6939f21

Please sign in to comment.