Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
factor out computing actual take amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Jun 14, 2014
1 parent ec524f9 commit 879a6ef
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions gittip/models/_mixin_team.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Teams on Gittip are plural participants with members.
"""
from collections import OrderedDict
from decimal import Decimal

from aspen.utils import typecheck
Expand Down Expand Up @@ -209,18 +210,34 @@ def get_team_take(self):
}
return membership

def compute_actual_takes(self):
"""Get the takes, compute the actual amounts, and return an OrderedDict.
"""
actual_takes = OrderedDict()
nominal_takes = self.get_takes()
nominal_takes.append(self.get_team_take())
budget = balance = self.receiving
for take in nominal_takes:
nominal_amount = take['nominal_amount'] = take.pop('amount')
actual_amount = take['actual_amount'] = min(nominal_amount, balance)
balance -= actual_amount
take['balance'] = balance
take['percentage'] = (actual_amount / budget) if budget > 0 else 0
actual_takes[take['member']] = take
return actual_takes

def get_members(self, current_participant):

This comment has been minimized.

Copy link
@chadwhitacre

chadwhitacre Jun 16, 2014

Contributor

IRC, re: test coverage.

"""Return a list of member dicts.
"""
assert self.IS_PLURAL
takes = self.get_takes()
takes.append(self.get_team_take())
budget = balance = self.receiving
takes = self.compute_actual_takes()
members = []
for take in takes:
for take in takes.values():
member = {}
member['username'] = take['member']
member['take'] = take['amount']
member['take'] = take['nominal_amount']
member['balance'] = take['balance']
member['percentage'] = take['percentage']

member['removal_allowed'] = current_participant == self
member['editing_allowed'] = False
Expand All @@ -234,9 +251,5 @@ def get_members(self, current_participant):

member['last_week'] = last_week = self.get_take_last_week_for(member)
member['max_this_week'] = self.compute_max_this_week(last_week)
amount = min(take['amount'], balance)
balance -= amount
member['balance'] = balance
member['percentage'] = (amount / budget) if budget > 0 else 0
members.append(member)
return members

2 comments on commit 879a6ef

@chadwhitacre
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the upshot of this commit for get_takes is that we're adding two new keys to the dicts it returns, yes?

  • nominal_amount—same as take
  • actual_amount—what the user would actually get based on the amount the team is project to receive next payday

@chadwhitacre
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit lgtm.

Please sign in to comment.