Skip to content

Commit

Permalink
fix: fix compliance period year of transfer 2095
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-valiollahi committed Jan 18, 2024
1 parent 0708d03 commit fcc5c11
Showing 1 changed file with 40 additions and 0 deletions.
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),
]

0 comments on commit fcc5c11

Please sign in to comment.