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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified to change handling of existing and updated due values
current_payment_instructions view used in place of the new payment_instructions_due table which has now been removed New update_due method added to participant to carry over existing due values to new (modified) payment instructions
- Loading branch information
Showing
4 changed files
with
30 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -854,10 +854,13 @@ def set_payment_instruction(self, team, amount, update_self=True, update_team=Tr | |
""" | ||
args = dict(participant=self.username, team=team.slug, amount=amount) | ||
t = (cursor or self.db).one(NEW_PAYMENT_INSTRUCTION, args) | ||
t_dict = t._asdict() | ||
|
||
if update_self: | ||
# Update giving amount of participant | ||
self.update_giving(cursor) | ||
# Carry over any existing due | ||
self.update_due(t_dict['team'],t_dict['id'],cursor) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
chadwhitacre
Contributor
|
||
if update_team: | ||
# Update receiving amount of team | ||
team.update_receiving(cursor) | ||
|
@@ -1002,6 +1005,31 @@ def update_giving(self, cursor=None): | |
|
||
return updated | ||
|
||
def update_due(self, team, id, cursor=None): | ||
"""Transfer existing due value to newly inserted record | ||
""" | ||
# Copy due to new record | ||
(cursor or self.db).run(""" | ||
UPDATE payment_instructions p | ||
SET due = COALESCE(( | ||
SELECT due | ||
FROM payment_instructions s | ||
WHERE participant=%(username)s | ||
AND team = %(team)s | ||
AND due > 0 | ||
), 0) | ||
WHERE p.id = %(id)s | ||
""", dict(username=self.username,team=team,id=id)) | ||
|
||
# Reset older due values to 0 | ||
(cursor or self.db).run(""" | ||
UPDATE payment_instructions p | ||
SET due = 0 | ||
WHERE participant = %(username)s | ||
AND team = %(team)s | ||
AND due > 0 | ||
AND p.id != %(id)s | ||
""", dict(username=self.username,team=team,id=id)) | ||
|
||
def update_taking(self, cursor=None): | ||
(cursor or self.db).run(""" | ||
|
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
I'm not sure this is necessary. When I added the
get_due
method in aa12b9d, I also added the ability to update theis_funded
anddue
fields of thepayment_instructions
table via thecurrent_payment_instructions
view (reusing a pattern from the oldcurrent_tips
view). It doesn't resetdue
(oris_funded
on non-current payment instructions, but that's not strictly necessary anyway (right?).