Skip to content

Commit

Permalink
feat(carbon_mixin.py): add check for carbon distribution usage in has…
Browse files Browse the repository at this point in the history
…_valid_carbon_distribution method
  • Loading branch information
jacopobacci committed Dec 19, 2024
1 parent 0f27725 commit 5f64777
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sustainability/models/carbon_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,7 @@ def create(self, vals):
# If we don't filter lines, they all get returned (in & out), whatever the carbon type
# It seems that the domain in the one2many field is not working as expected...
def _get_distribution_lines(self, carbon_type: str):
return self[f"carbon_{carbon_type}_distribution_line_ids"].filtered(
lambda x: x.carbon_type == carbon_type
)
return self[f"carbon_{carbon_type}_distribution_line_ids"]

def has_valid_carbon_value(self, carbon_type: str):
self.ensure_one()
Expand All @@ -402,6 +400,8 @@ def has_valid_carbon_value(self, carbon_type: str):

def has_valid_carbon_distribution(self, carbon_type: str):
self.ensure_one()
if not self[f"carbon_{carbon_type}_use_distribution"]:
return True
total_percentage = sum(
[line.percentage for line in self._get_distribution_lines(carbon_type)]
)
Expand Down

0 comments on commit 5f64777

Please sign in to comment.