-
-
Notifications
You must be signed in to change notification settings - Fork 714
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] product_attribute_variant_rules: Review fixes
- Loading branch information
1 parent
4b8f3cc
commit 6939f21
Showing
2 changed files
with
5 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | ||
|
@@ -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 | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters