-
Notifications
You must be signed in to change notification settings - Fork 13
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 bring release-1.22.0 to master - Sprint 32 (…
…Franklin) (#608)
- Loading branch information
1 parent
8bf2f8f
commit 8493985
Showing
63 changed files
with
1,965 additions
and
552 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
70 changes: 70 additions & 0 deletions
70
backend/api/fixtures/operational/0024_update_roles_permissions.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,70 @@ | ||
from django.db import transaction | ||
|
||
from api.management.data_script import OperationalDataScript | ||
from api.models.permission import Permission | ||
from api.models.role import Role | ||
from api.models.role_permission import RolePermission | ||
from api.authorities import REQUIRED_AUTHORITIES | ||
|
||
|
||
class UpdateRolesPermissions(OperationalDataScript): | ||
""" | ||
Adds the Roles and Permissions | ||
""" | ||
is_revertable = False | ||
comment = 'Adds new permission' | ||
|
||
def check_run_preconditions(self): | ||
return True | ||
|
||
def update_permissions(self): | ||
Permission.objects.get_or_create( | ||
permission_code="VIEW_BCEID_NOTIFICATIONS", | ||
defaults={ | ||
'name': "View BceID Notifications", | ||
'description': "can view notification list for BCEID" | ||
} | ||
) | ||
|
||
def update_signing_authority(self): | ||
permissions_to_be_added = [ | ||
'VIEW_BCEID_NOTIFICATIONS' | ||
] | ||
|
||
role = Role.objects.get( | ||
role_code="Signing Authority" | ||
) | ||
|
||
for permission_code in permissions_to_be_added: | ||
permission = Permission.objects.get(permission_code=permission_code) | ||
RolePermission.objects.get_or_create( | ||
permission=permission, | ||
role=role | ||
) | ||
|
||
def update_zeva_user(self): | ||
permissions_to_be_added = [ | ||
'VIEW_BCEID_NOTIFICATIONS' | ||
] | ||
|
||
role = Role.objects.get( | ||
role_code="ZEVA User" | ||
) | ||
|
||
for permission_code in permissions_to_be_added: | ||
permission = Permission.objects.get(permission_code=permission_code) | ||
RolePermission.objects.get_or_create( | ||
permission=permission, | ||
role=role | ||
) | ||
|
||
@transaction.atomic | ||
def run(self): | ||
self.update_permissions() | ||
self.update_zeva_user() | ||
self.update_signing_authority() | ||
|
||
print('Updated Permissions') | ||
|
||
|
||
script_class = UpdateRolesPermissions |
55 changes: 55 additions & 0 deletions
55
backend/api/fixtures/operational/0025_update_notifications.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,55 @@ | ||
from django.db import transaction | ||
|
||
from api.management.data_script import OperationalDataScript | ||
from api.models.notification import Notification | ||
from api.models.permission import Permission | ||
|
||
|
||
class UpdateNotifications(OperationalDataScript): | ||
""" | ||
Update notifications permission | ||
""" | ||
is_revertable = False | ||
comment = 'Update notifications permission' | ||
|
||
def check_run_preconditions(self): | ||
return True | ||
def update_notifications(self): | ||
permission = Permission.objects.get(permission_code="VIEW_BCEID_NOTIFICATIONS") | ||
notification = Notification.objects.get(notification_code="CREDIT_APPLICATION_ISSUED") | ||
notification.permission = permission | ||
notification.save() | ||
notification = Notification.objects.get(notification_code="CREDIT_TRANSFER_APPROVED_PARTNER") | ||
notification.permission = permission | ||
notification.save() | ||
notification = Notification.objects.get(notification_code="CREDIT_TRANSFER_RECORDED") | ||
notification.permission = permission | ||
notification.save() | ||
notification = Notification.objects.get(notification_code="CREDIT_TRANSFER_REJECTED_PARTNER") | ||
notification.permission = permission | ||
notification.save() | ||
notification = Notification.objects.get(notification_code="CREDIT_TRANSFER_REJECTED") | ||
notification.permission = permission | ||
notification.save() | ||
notification = Notification.objects.get(notification_code="CREDIT_TRANSFER_RESCINDED_PARTNER") | ||
notification.permission = permission | ||
notification.save() | ||
notification = Notification.objects.get(notification_code="CREDIT_TRANSFER_SUBMITTED") | ||
notification.permission = permission | ||
notification.save() | ||
notification = Notification.objects.get(notification_code="ZEV_MODEL_REJECTED") | ||
notification.permission = permission | ||
notification.save() | ||
notification = Notification.objects.get(notification_code="ZEV_MODEL_RANGE_REPORT_TEST_RESULT_REQUESTED") | ||
notification.permission = permission | ||
notification.save() | ||
notification = Notification.objects.get(notification_code="ZEV_MODEL_VALIDATED") | ||
notification.permission = permission | ||
notification.save() | ||
|
||
@transaction.atomic | ||
def run(self): | ||
self.update_notifications() | ||
|
||
|
||
script_class = UpdateNotifications |
34 changes: 34 additions & 0 deletions
34
backend/api/fixtures/operational/0026_update_notifications.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,34 @@ | ||
from django.db import transaction | ||
|
||
from api.management.data_script import OperationalDataScript | ||
from api.models.notification import Notification | ||
from api.models.permission import Permission | ||
|
||
|
||
class UpdateNotifications(OperationalDataScript): | ||
""" | ||
Update notifications permission | ||
""" | ||
is_revertable = False | ||
comment = 'Update notifications permission' | ||
|
||
def check_run_preconditions(self): | ||
return True | ||
def update_notifications(self): | ||
permission = Permission.objects.get(permission_code="EDIT_ZEV") | ||
notification = Notification.objects.get(notification_code="ZEV_MODEL_REJECTED") | ||
notification.permission = permission | ||
notification.save() | ||
notification = Notification.objects.get(notification_code="ZEV_MODEL_RANGE_REPORT_TEST_RESULT_REQUESTED") | ||
notification.permission = permission | ||
notification.save() | ||
notification = Notification.objects.get(notification_code="ZEV_MODEL_VALIDATED") | ||
notification.permission = permission | ||
notification.save() | ||
|
||
@transaction.atomic | ||
def run(self): | ||
self.update_notifications() | ||
|
||
|
||
script_class = UpdateNotifications |
140 changes: 140 additions & 0 deletions
140
backend/api/serializers/compliance_obligation_activity.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,140 @@ | ||
from datetime import date | ||
from django.db.models import Sum, Value, Q | ||
from rest_framework import serializers | ||
from api.serializers.credit_transaction import CreditTransactionListSerializer, \ | ||
CreditTransactionBalanceSerializer, CreditTransactionSerializer | ||
from api.models.account_balance import AccountBalance | ||
from api.models.vehicle import Vehicle | ||
from api.models.sales_submission import SalesSubmission | ||
from api.models.vehicle_statuses import VehicleDefinitionStatuses | ||
from api.models.credit_transaction import CreditTransaction | ||
from api.serializers.credit_transaction import CreditClassSerializer, CreditTransactionObligationActivitySerializer | ||
from api.serializers.account_balance import AccountBalanceSerializer | ||
from api.serializers.organization import OrganizationSerializer | ||
from api.serializers.sales_submission import SalesSubmissionListSerializer, SalesSubmissionObligationActivitySerializer | ||
|
||
|
||
class ComplianceObligationActivityDetailsSerializer(serializers.ModelSerializer): | ||
""" | ||
""" | ||
prior_year_balance = serializers.SerializerMethodField() | ||
report_year_balance = serializers.SerializerMethodField() | ||
report_year_transactions = serializers.SerializerMethodField() | ||
pending_balance = serializers.SerializerMethodField() | ||
|
||
def retrieve_balance(self, year, credit_type): | ||
request = self.context.get('request') | ||
balance = AccountBalance.objects.filter( | ||
organization=request.user.organization, | ||
effective_date__lte=date(year, 9, 30), | ||
credit_class_id=credit_type | ||
).order_by('-effective_date').first() | ||
if balance: | ||
return balance.balance | ||
else: | ||
return 0 | ||
|
||
def get_prior_year_balance(self, obj, *args, **kwargs): | ||
kwargs = self.context.get('kwargs') | ||
report_year = int(kwargs.get('year')) | ||
prior_year = report_year-1 | ||
prior_year_balance_a = self.retrieve_balance(prior_year, 1) | ||
prior_year_balance_b = self.retrieve_balance(prior_year, 2) | ||
return {'year': prior_year, 'a': prior_year_balance_a, 'b': prior_year_balance_b} | ||
|
||
def get_report_year_balance(self, obj, *args, **kwargs): | ||
kwargs = self.context.get('kwargs') | ||
report_year = int(kwargs.get('year')) | ||
report_year_balance_a = self.retrieve_balance(report_year, 1) | ||
report_year_balance_b = self.retrieve_balance(report_year, 2) | ||
return {'year': report_year, 'a': report_year_balance_a, 'b': report_year_balance_b} | ||
|
||
def get_report_year_transactions(self, obj, *args, **kwargs): | ||
request = self.context.get('request') | ||
kwargs = self.context.get('kwargs') | ||
report_year = int(kwargs.get('year')) | ||
transfers_in = CreditTransaction.objects.filter( | ||
credit_to=request.user.organization, | ||
transaction_type__transaction_type='Credit Transfer', | ||
transaction_timestamp__lte=date(report_year, 9, 30), | ||
transaction_timestamp__gte=date(report_year-1, 10, 1), | ||
).values( | ||
'credit_class_id', 'model_year_id' | ||
).annotate( | ||
total_value=Sum('total_value') | ||
).order_by( | ||
'credit_class_id', 'model_year_id' | ||
) | ||
|
||
transfers_out = CreditTransaction.objects.filter( | ||
debit_from=request.user.organization, | ||
transaction_type__transaction_type='Credit Transfer', | ||
transaction_timestamp__lte=date(report_year, 9, 30), | ||
transaction_timestamp__gte=date(report_year-1, 10, 1), | ||
).values( | ||
'credit_class_id', 'model_year_id' | ||
).annotate(total_value=Sum( | ||
'total_value') | ||
).order_by( | ||
'credit_class_id', 'model_year_id' | ||
) | ||
|
||
credits_issued_sales = CreditTransaction.objects.filter( | ||
credit_to=request.user.organization, | ||
transaction_type__transaction_type='Validation', | ||
transaction_timestamp__lte=date(report_year, 9, 30), | ||
transaction_timestamp__gte=date(report_year-1, 10, 1), | ||
).values( | ||
'credit_class_id', 'model_year_id' | ||
).annotate( | ||
total_value=Sum('total_value') | ||
).order_by( | ||
'credit_class_id', 'model_year_id' | ||
) | ||
|
||
transfers_in_serializer = CreditTransactionObligationActivitySerializer(transfers_in, read_only=True, many=True) | ||
transfers_out_serializer = CreditTransactionObligationActivitySerializer(transfers_out, read_only=True, many=True) | ||
credit_sales_serializer = CreditTransactionObligationActivitySerializer(credits_issued_sales, read_only=True, many=True) | ||
content = { | ||
'transfers_in': transfers_in_serializer.data, | ||
'transfers_out': transfers_out_serializer.data, | ||
'credits_issued_sales': credit_sales_serializer.data | ||
} | ||
return content | ||
|
||
def get_pending_balance(self, obj, *args, **kwargs): | ||
kwargs = self.context.get('kwargs') | ||
report_year = int(kwargs.get('year')) | ||
request = self.context.get('request') | ||
pending_sales_submissions = SalesSubmission.objects.filter( | ||
organization=request.user.organization, | ||
validation_status__in=['SUBMITTED', 'RECOMMEND_APPROVAL', 'RECOMMEND_REJECTION', 'CHECKED'], | ||
submission_date__lte=date(report_year, 9, 30), | ||
submission_date__gte=date(report_year-1, 10, 1), | ||
) | ||
totals = {} | ||
for obj in pending_sales_submissions: | ||
for record in obj.get_content_totals_by_vehicles(): | ||
try: | ||
model_year = float(record['xls_model_year']) | ||
except ValueError: | ||
continue | ||
vehicle = Vehicle.objects.filter( | ||
make__iexact=record['xls_make'], | ||
model_name=record['xls_model'], | ||
model_year__name=int(model_year), | ||
validation_status=VehicleDefinitionStatuses.VALIDATED, | ||
).first() | ||
if vehicle: | ||
model_year_str = str(int(model_year)) | ||
if model_year_str not in totals.keys(): | ||
totals[model_year_str] = {'A': 0, 'B': 0} | ||
totals[model_year_str][vehicle.get_credit_class()] += vehicle.get_credit_value() * record['num_vins'] | ||
return totals | ||
|
||
class Meta: | ||
model = CreditTransaction | ||
fields = ( | ||
'report_year_balance', 'pending_balance', | ||
'prior_year_balance', 'report_year_transactions' | ||
) |
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
Oops, something went wrong.