This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Charge in arrears #3675
Merged
Merged
Charge in arrears #3675
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ae1bb5b
Preliminary commit - charging in arrears
rorepo 3e6d07a
Schema changes moved to branch.sql
rorepo 3255f9f
Clean up code formatting
chadwhitacre 55304a2
Remove extraneous argument
chadwhitacre fd67faa
Refined and added tests
rorepo 2eafbe7
Code formatting and cleanup
rorepo 58342d2
Kill park_payment_instructions method
chadwhitacre 01a403c
Trim trailing whitespace
chadwhitacre cf1bbfd
Removed extraneous table script
rorepo 0bb82a5
Renamed payment_instructions 'giving_due' to 'due'
rorepo 6702cc3
Fix whitespace typo
chadwhitacre f9ab3a5
Updated and added tests and history logging
rorepo 388ff12
Updated yaml fixtures corresponding to new tests
rorepo aa12b9d
Add a Participant.get_due(team) method
chadwhitacre 105082b
Modified to change handling of existing and updated due values
rorepo af32724
Reflow for 100-char lines
chadwhitacre 3d6e986
Add some whitespace between args
chadwhitacre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
BEGIN; | ||
|
||
ALTER TABLE payment_instructions ADD COLUMN due numeric(35,2) DEFAULT 0; | ||
|
||
-- Recreate the current_payment_instructions view to pick up due. | ||
DROP VIEW current_payment_instructions; | ||
CREATE VIEW current_payment_instructions AS | ||
SELECT DISTINCT ON (participant, team) * | ||
FROM payment_instructions | ||
ORDER BY participant, team, mtime DESC; | ||
|
||
-- Allow updating is_funded and due via the current_payment_instructions view for convenience. | ||
DROP FUNCTION update_payment_instruction(); | ||
CREATE FUNCTION update_payment_instruction() RETURNS trigger AS $$ | ||
BEGIN | ||
UPDATE payment_instructions | ||
SET is_funded = NEW.is_funded | ||
, due = NEW.due | ||
WHERE id = NEW.id; | ||
RETURN NULL; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
CREATE TRIGGER update_current_payment_instruction | ||
INSTEAD OF UPDATE ON current_payment_instructions | ||
FOR EACH ROW EXECUTE PROCEDURE update_payment_instruction(); | ||
END; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This subquery can be replaced with a query against
current_payment_instructions
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current subquery has this:
WHERE mtime < %(ts_start)s
while
current_payment_instructions
does not.Can this be a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we'll need to move that
WHERE
clause up into the parent query.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it,
ts_start
is defined at the start of payday. This would make itdifficult to incorporate this into the
current_payment_instructions
view as a condition that would be meaningful at other times as well as at payday.Moving the condition into the parent query may not help, if
current_payment_instructions
has already picked up an incorrect record as the current one.I'd also like to understand the situation where
mtime
inpayment_instructions
could/would be >= payday
ts_start
. e.g. can a user specify a start time that is in the future,for a subscription? Was unable to find any such provision in the dev environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made all changes except for this particular one, because I'm not sure about the filtering by
ts_start
. As I see it,payment_instructions
can only have a record withmtime
>ts_start
if a new subscription is created after the payday run has been started. And if this situation comes up, we do have a problem - thecurrent_payment_instructions
view will pick up this latest record, whilepayday_payment_instructions
(as it is now) will not. If we do update the subquery, this could have different results depending on the exact point in payday when the new subscription is created.Once again, I've got a 'diverged' situation after rebasing with master:
However, this seems ok after checking the log - will just have to do a forced push like last time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Withdrawn. :-)