-
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.
Tracking pull request to merge release-2.13.0 to master (#2723)
* update to 2.13.0 * update pr number * feat: enabled visibility of credit transfer agreement date and categorization for BCeID users BCeID users can now view the date of the written agreement and both potential and final categorization in the Transaction History section. * fix: credit trade transactions assigning category when not needed * fix: create migration file * refactor: added migration to update expirations for two signing authority assertions * fix: sql script * fix: trade category if statement * Fix: TFRS - Roles page throwing an error for BCeID users 197 * fix: fixed migration ordering * fix: migration updating missing rescinded history items --------- Co-authored-by: Hamed Valiollahi Bayeki <[email protected]> Co-authored-by: Kevin Hashimoto <[email protected]> Co-authored-by: Alex Zorkin <[email protected]> Co-authored-by: Prashanth <[email protected]> Co-authored-by: Your Name <[email protected]>
- Loading branch information
1 parent
5406b60
commit 6f4ddae
Showing
12 changed files
with
134 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Generated by Django 3.2.23 on 2023-11-06 23:13 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api', '0010_migrate_compliance_report'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunSQL("UPDATE credit_trade SET trade_category_id = null FROM credit_trade_type WHERE credit_trade.trade_category_id IS NOT NULL AND credit_trade_type.id = credit_trade.trade_category_id AND credit_trade_type.the_type NOT IN ('Buy', 'Sell');") | ||
] |
39 changes: 39 additions & 0 deletions
39
backend/api/migrations/0012_update_signing_authority_assertion_expirations.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,39 @@ | ||
import logging | ||
from django.db import migrations, transaction | ||
from django.utils import timezone | ||
|
||
def update_expiration_dates(apps, schema_editor): | ||
""" | ||
Sets new expiration dates for specific SigningAuthorityAssertion records | ||
If any record is not updated, all changes are reverted. | ||
""" | ||
signing_authority_assertion = apps.get_model('api', 'SigningAuthorityAssertion') | ||
new_expiration_date = timezone.datetime.strptime('2023-11-06', "%Y-%m-%d").date() | ||
|
||
# IDs of the SigningAuthorityAssertion records to update | ||
assertion_ids = [2, 3] | ||
|
||
with transaction.atomic(): | ||
for assertion_id in assertion_ids: | ||
try: | ||
assertion = signing_authority_assertion.objects.get(id=assertion_id) | ||
assertion.expiration_date = new_expiration_date | ||
assertion.save() | ||
except signing_authority_assertion.DoesNotExist: | ||
logging.warning( | ||
'Failed to update SigningAuthorityAssertion: No entry found with id "%s"; ' | ||
'all changes within this transaction will be reverted.', | ||
assertion_id | ||
) | ||
|
||
class Migration(migrations.Migration): | ||
""" | ||
Attaches the update function to the migration operations | ||
""" | ||
dependencies = [ | ||
('api', '0011_credit_trade_category'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(update_expiration_dates), | ||
] |
59 changes: 59 additions & 0 deletions
59
backend/api/migrations/0013_create_missing_rescinded_history_records.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,59 @@ | ||
from django.db import migrations | ||
from django.core.exceptions import ValidationError | ||
|
||
def create_missing_credit_trade_history(apps, schema_editor): | ||
CreditTrade = apps.get_model('api', 'CreditTrade') | ||
CreditTradeHistory = apps.get_model('api', 'CreditTradeHistory') | ||
User = apps.get_model('auth', 'User') | ||
Role = apps.get_model('api', 'Role') | ||
|
||
for credit_trade in CreditTrade.objects.filter(is_rescinded=True): | ||
if not CreditTradeHistory.objects.filter(credit_trade_id=credit_trade.id, is_rescinded=True).exists(): | ||
user = credit_trade.create_user if credit_trade.create_user else User.objects.first() | ||
|
||
user_roles = Role.objects.filter(user_roles__user_id=user.id) | ||
|
||
role_id = None | ||
if user_roles.filter(name="GovDirector").exists(): | ||
role_id = user_roles.get(name="GovDirector").id | ||
elif user_roles.filter(name="GovDeputyDirector").exists(): | ||
role_id = user_roles.get(name="GovDeputyDirector").id | ||
elif user_roles.exists(): | ||
role_id = user_roles.first().id | ||
|
||
history = CreditTradeHistory( | ||
credit_trade_id=credit_trade.id, | ||
respondent_id=credit_trade.respondent.id, | ||
status_id=credit_trade.status.id, | ||
type_id=credit_trade.type.id, | ||
number_of_credits=credit_trade.number_of_credits, | ||
fair_market_value_per_credit=credit_trade.fair_market_value_per_credit, | ||
zero_reason_id=credit_trade.zero_reason.id if credit_trade.zero_reason else None, | ||
trade_effective_date=credit_trade.trade_effective_date, | ||
compliance_period_id=credit_trade.compliance_period.id if credit_trade.compliance_period else None, | ||
is_rescinded=True, | ||
create_user=user, | ||
user_role_id=role_id, | ||
date_of_written_agreement=credit_trade.date_of_written_agreement, | ||
category_d_selected=credit_trade.category_d_selected | ||
) | ||
|
||
try: | ||
history.full_clean() | ||
history.save() | ||
except ValidationError as error: | ||
# Handle validation error if necessary | ||
raise ValidationError(error) | ||
|
||
# Update the create_timestamp field | ||
history.create_timestamp = credit_trade.update_timestamp | ||
history.save(update_fields=['create_timestamp']) | ||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('api', '0012_update_signing_authority_assertion_expirations'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(create_missing_credit_trade_history), | ||
] |
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
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