Skip to content

Commit

Permalink
Merge pull request #353 from jamesggraf/zero-volume-fix
Browse files Browse the repository at this point in the history
Prevent divide by zero error when keg volume is set to zero
  • Loading branch information
mik3y authored Mar 1, 2017
2 parents 4f51031 + e533f68 commit 2813a46
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pykeg/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,8 @@ def remaining_volume_ml(self):
return self.full_volume_ml - self.served_volume_ml - self.spilled_ml

def percent_full(self):
if self.full_volume_ml is None or self.full_volume_ml <= 0:
return 0
result = float(self.remaining_volume_ml()) / float(self.full_volume_ml) * 100
result = max(min(result, 100), 0)
return result
Expand Down

0 comments on commit 2813a46

Please sign in to comment.