Skip to content

Commit

Permalink
Merge pull request #2808 from bcgov/fix/hamed-correct-effective-date-…
Browse files Browse the repository at this point in the history
…of-transfer-2095-2768

Fix: Fix compliance period year of transfer 2095 - 2768
  • Loading branch information
AlexZorkin authored Jan 19, 2024
2 parents 99fe06c + fcc5c11 commit 4d80c71
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 4d80c71

Please sign in to comment.