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

Commit

Permalink
Store minimum_charge in the database
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre authored and rohitpaulk committed Jan 27, 2016
1 parent bf6d6b4 commit 5f75997
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gratipay/billing/payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


with open('sql/payday.sql') as f:
PAYDAY = f.read() % {'minimum_charge': MINIMUM_CHARGE}
PAYDAY = f.read()


class ExceptionWrapped(Exception): pass
Expand Down
1 change: 1 addition & 0 deletions gratipay/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def clear_tables(self):
except (IntegrityError, InternalError):
tablenames.insert(0, tablename)
self.db.run("ALTER SEQUENCE participants_id_seq RESTART WITH 1")
self.db.run("INSERT INTO settings DEFAULT VALUES")


def make_elsewhere(self, platform, user_id, user_name, **kw):
Expand Down
3 changes: 3 additions & 0 deletions gratipay/wireup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def db(env):
db.register_model(model)
gratipay.billing.payday.Payday.db = db

from gratipay.billing.exchanges import MINIMUM_CHARGE
db.run('UPDATE settings SET minimum_charge=%s', (MINIMUM_CHARGE,))

return db

def mail(env, project_root='.'):
Expand Down
2 changes: 2 additions & 0 deletions sql/branch.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
BEGIN;
UPDATE payment_instructions SET due = 0 WHERE amount = 0 AND due != 0;
UPDATE payment_instructions SET due = floor(9.41/(amount)) * amount WHERE due > 9.41;
CREATE TABLE settings (minimum_charge numeric(35,2) DEFAULT NULL);
INSERT INTO settings DEFAULT VALUES;
END;
2 changes: 1 addition & 1 deletion sql/payday.sql
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ CREATE OR REPLACE FUNCTION process_payment_instruction() RETURNS trigger AS $$
IF (NEW.amount + NEW.due <= participant.new_balance OR participant.card_hold_ok) THEN
EXECUTE pay(NEW.participant, NEW.team, NEW.amount + NEW.due, 'to-team');
RETURN NEW;
ELSIF NEW.amount + NEW.due <= %(minimum_charge)s THEN
ELSIF NEW.amount + NEW.due <= (SELECT minimum_charge FROM settings) THEN
EXECUTE park(NEW.participant, NEW.team, NEW.amount + NEW.due);
END IF;

Expand Down

0 comments on commit 5f75997

Please sign in to comment.