Skip to content

Commit

Permalink
vary the initial take of new team members
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed May 18, 2021
1 parent 1520c7b commit b55b372
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion liberapay/models/_mixin_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,19 @@ def add_member(self, member, cursor=None):
raise MemberLimitReached
if member.status != 'active':
raise InactiveParticipantAdded
self.set_take_for(member, Money(-1, member.main_currency), self, cursor=cursor)
n_auto_takes, n_manual_takes = (cursor or self.db).one("""
SELECT sum(t.amount < 0) AS n_auto_takes
, sum(t.amount >= 0) AS n_manual_takes
FROM current_takes t
WHERE t.team = %s
""", (self.id,), default=(0, 0))
if n_auto_takes == 0 and n_manual_takes > 0:
# If the team only has manual takes, then the new member should
# start at zero instead of taking all the leftover.
initial_take = Money.ZEROS[member.main_currency]
else:
initial_take = Money(-1, member.main_currency)
self.set_take_for(member, initial_take, self, cursor=cursor)

def remove_all_members(self, cursor=None):
(cursor or self.db).run("""
Expand Down

0 comments on commit b55b372

Please sign in to comment.