-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #779 from liberapay/currencies-4
Currencies - part 4
- Loading branch information
Showing
12 changed files
with
91 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
BEGIN; | ||
CREATE FUNCTION coalesce_currency_amount(currency_amount, currency) RETURNS currency_amount AS $$ | ||
BEGIN RETURN (COALESCE($1.amount, '0.00'::numeric), COALESCE($1.currency, $2)); END; | ||
$$ LANGUAGE plpgsql IMMUTABLE; | ||
CREATE OR REPLACE FUNCTION initialize_amounts() RETURNS trigger AS $$ | ||
BEGIN | ||
NEW.giving = coalesce_currency_amount(NEW.giving, NEW.main_currency); | ||
NEW.receiving = coalesce_currency_amount(NEW.receiving, NEW.main_currency); | ||
NEW.taking = coalesce_currency_amount(NEW.taking, NEW.main_currency); | ||
NEW.leftover = coalesce_currency_amount(NEW.leftover, NEW.main_currency); | ||
NEW.balance = coalesce_currency_amount(NEW.balance, NEW.main_currency); | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
DROP TRIGGER initialize_amounts ON participants; | ||
CREATE TRIGGER initialize_amounts | ||
BEFORE INSERT OR UPDATE ON participants | ||
FOR EACH ROW EXECUTE PROCEDURE initialize_amounts(); | ||
END; |
Oops, something went wrong.