diff --git a/gratipay/billing/payday.py b/gratipay/billing/payday.py index 80469197cb..77bdb58d05 100644 --- a/gratipay/billing/payday.py +++ b/gratipay/billing/payday.py @@ -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 diff --git a/gratipay/testing/__init__.py b/gratipay/testing/__init__.py index 257f9095f4..f7f30856b5 100644 --- a/gratipay/testing/__init__.py +++ b/gratipay/testing/__init__.py @@ -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): diff --git a/gratipay/wireup.py b/gratipay/wireup.py index c93138dfdd..ad9ffe6844 100644 --- a/gratipay/wireup.py +++ b/gratipay/wireup.py @@ -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='.'): diff --git a/sql/branch.sql b/sql/branch.sql index d1a0104b1c..da34be2382 100644 --- a/sql/branch.sql +++ b/sql/branch.sql @@ -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; diff --git a/sql/payday.sql b/sql/payday.sql index 42029d8aa2..a6e1701a98 100644 --- a/sql/payday.sql +++ b/sql/payday.sql @@ -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;