-
Notifications
You must be signed in to change notification settings - Fork 40
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 #361 from bcgov/release-v0.2.0
Release v0.2.0.4
- Loading branch information
Showing
6 changed files
with
83 additions
and
27 deletions.
There are no files selected for viewing
Empty file.
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,48 @@ | ||
from api.models.CreditTrade import CreditTrade | ||
from api.models.CreditTradeHistory import CreditTradeHistory | ||
from api.models.CreditTradeStatus import CreditTradeStatus | ||
|
||
|
||
def run(): | ||
status_approved = CreditTradeStatus.objects \ | ||
.get(status="Approved") | ||
|
||
status_completed = CreditTradeStatus.objects \ | ||
.get(status="Completed") | ||
|
||
# Get all completed credit transfers | ||
credit_trades = CreditTrade.objects.filter( | ||
status_id=status_completed.id).order_by('-id') | ||
|
||
for credit_trade in credit_trades: | ||
''' | ||
as we loop through the completed credit trades, | ||
look at the history, and check what the last effective was | ||
before it was completed | ||
''' | ||
credit_trade_history = CreditTradeHistory.objects.filter( | ||
credit_trade_id=credit_trade.id, | ||
status_id=status_approved.id | ||
).order_by('-update_timestamp', '-id').first() | ||
|
||
if credit_trade_history: | ||
credit_trade_history_complete = CreditTradeHistory.objects.filter( | ||
credit_trade_id=credit_trade.id, | ||
status_id=status_completed.id | ||
).order_by('-update_timestamp', '-id').first() | ||
|
||
if credit_trade_history_complete.trade_effective_date != \ | ||
credit_trade_history.trade_effective_date and \ | ||
credit_trade_history.trade_effective_date is not None: | ||
''' | ||
Update the history that has a status completed | ||
so it uses the that effective date | ||
''' | ||
credit_trade_history_complete.trade_effective_date = \ | ||
credit_trade_history.trade_effective_date | ||
credit_trade_history_complete.save() | ||
|
||
# Update the credit trade | ||
credit_trade.trade_effective_date = \ | ||
credit_trade_history.trade_effective_date | ||
credit_trade.save() |
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