-
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.
fix: fix compliance period year of transfer 2095
- Loading branch information
1 parent
0708d03
commit fcc5c11
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
backend/api/migrations/0021_correct_compliance_period_of_transfer_2095.py
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,40 @@ | ||
import logging | ||
from django.db import migrations, transaction | ||
|
||
def update_credit_trade_history(apps, schema_editor): | ||
""" | ||
Update transfer ID #2095 to correct compliance period to the year 2023 (compliance_period_id=13) | ||
from the previous year 2022 (compliance_period_id=12) | ||
If any record is not updated, all changes are reverted. | ||
""" | ||
credit_trade_history = apps.get_model('api', 'CreditTradeHistory') | ||
new_compliance_period_id = 13 | ||
|
||
# IDs of the CreditTradeHistory records to update | ||
history_ids = [978, 979] | ||
|
||
with transaction.atomic(): | ||
for history_id in history_ids: | ||
try: | ||
history = credit_trade_history.objects.get(id=history_id) | ||
history.compliance_period_id = new_compliance_period_id | ||
history.save() | ||
except credit_trade_history.DoesNotExist: | ||
logging.warning( | ||
'Failed to update CreditTradeHistory: No entry found with id "%s"; ' | ||
'all changes within this transaction will be reverted.', | ||
history_id | ||
) | ||
|
||
class Migration(migrations.Migration): | ||
""" | ||
Attaches the update function to the migration operations | ||
""" | ||
dependencies = [ | ||
('api', '0020_correct_effective_date_of_transfer_2095'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(update_credit_trade_history, reverse_code=migrations.RunPython.noop), | ||
] |