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

Commit

Permalink
Remove the settle_tip_graph function entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed May 14, 2015
1 parent 3fdcb2d commit abc522c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
17 changes: 3 additions & 14 deletions gratipay/billing/payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ def payin(self):
self.db.run("""
DROP FUNCTION process_take();
DROP FUNCTION process_tip();
DROP FUNCTION settle_tip_graph();
DROP FUNCTION transfer(text, text, numeric, context_type);
""")

Expand Down Expand Up @@ -274,17 +273,9 @@ def f(p):

@staticmethod
def transfer_tips(cursor):
cursor.run("""
UPDATE payday_tips t
SET is_funded = true
FROM payday_participants p
WHERE p.username = t.tipper
AND p.card_hold_ok;
SELECT settle_tip_graph();
""")
"""Trigger the process_tip function for each row in payday_tips.
"""
cursor.run("UPDATE payday_tips SET is_funded=true;")


@staticmethod
Expand All @@ -310,8 +301,6 @@ def transfer_takes(cursor, ts_start):
) IS NULL
ORDER BY t.team, t.ctime DESC;
SELECT settle_tip_graph();
""", dict(ts_start=ts_start))


Expand Down
11 changes: 0 additions & 11 deletions sql/payday.sql
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,6 @@ CREATE TRIGGER process_take AFTER INSERT ON payday_takes
FOR EACH ROW EXECUTE PROCEDURE process_take();


-- Create a function to settle whole tip graph

CREATE OR REPLACE FUNCTION settle_tip_graph() RETURNS void AS $$
BEGIN
UPDATE payday_tips
SET is_funded = true
WHERE is_funded IS NOT true;
END;
$$ LANGUAGE plpgsql;


-- Save the stats we already have

UPDATE paydays
Expand Down
4 changes: 1 addition & 3 deletions tests/py/test_billing_payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,14 @@ def test_payin_doesnt_make_null_transfers(self):
assert not transfers0

def test_transfer_tips(self):
alice = self.make_participant('alice', claimed_time='now', balance=1,
last_bill_result='')
alice = self.make_participant('alice', claimed_time='now', balance=1)
alice.set_tip_to(self.janet, D('0.51'))
alice.set_tip_to(self.homer, D('0.50'))
payday = Payday.start()
with self.db.get_cursor() as cursor:
payday.prepare(cursor, payday.ts_start)
payday.transfer_tips(cursor)
payday.update_balances(cursor)
alice = Participant.from_id(alice.id)
assert Participant.from_id(alice.id).balance == D('0.49')
assert Participant.from_id(self.janet.id).balance == D('0.51')
assert Participant.from_id(self.homer.id).balance == 0
Expand Down

0 comments on commit abc522c

Please sign in to comment.