Skip to content

Commit

Permalink
Track pull request NEW to merge release-1.25.0 to master (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuanfandevops authored May 6, 2021
1 parent 4f7c723 commit d25511f
Show file tree
Hide file tree
Showing 31 changed files with 1,221 additions and 772 deletions.
36 changes: 36 additions & 0 deletions backend/api/fixtures/operational/0028_update_model_year.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django.db import transaction

from api.management.data_script import OperationalDataScript
from api.models.model_year import ModelYear


class UpdateModelYear(OperationalDataScript):
"""
Add 2022-2023 model years
"""
is_revertable = False
comment = 'Add 2022-2023 model years'

def check_run_preconditions(self):
return True

@transaction.atomic
def run(self):
ModelYear.objects.update_or_create(
name="2022",
defaults={
'effective_date': "2022-01-01",
'expiration_date': "2022-12-31"
}
)

ModelYear.objects.update_or_create(
name="2023",
defaults={
'effective_date': "2023-01-01",
'expiration_date': "2023-12-31"
}
)


script_class = UpdateModelYear
33 changes: 33 additions & 0 deletions backend/api/fixtures/operational/0029_update_notifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.db import transaction

from api.management.data_script import OperationalDataScript
from api.models.notification import Notification


class UpdateNotifications(OperationalDataScript):
"""
Update notifications name
"""
is_revertable = False
comment = 'Update notifications name'

def check_run_preconditions(self):
return True

def update_notifications(self):
notification = Notification.objects.get(notification_code="CREDIT_APPLICATION_ISSUED")
notification.name = "Credit Application Processed by the Government of B.C"
notification.save()
notification = Notification.objects.get(notification_code="CREDIT_TRANSFER_RECORDED")
notification.name = "Credit Transfer Recorded by the Government of B.C."
notification.save()
notification = Notification.objects.get(notification_code="CREDIT_TRANSFER_REJECTED")
notification.name = "Credit Transfer Rejected by the Government of B.C."
notification.save()

@transaction.atomic
def run(self):
self.update_notifications()


script_class = UpdateNotifications
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Meta:
model = ModelYearReportCreditOffset
fields = (
'credit_a_offset_value', 'credit_b_offset_value',
'model_year'
'model_year', 'model_year_report'
)


Expand Down Expand Up @@ -96,15 +96,15 @@ def get_prior_year_balance(self, obj, *args, **kwargs):
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):
## this is actually being calculated on the frontend and not used
kwargs = self.context.get('kwargs')
report_id = int(kwargs.get('id'))
report_year = self.retrieve_year(report_id)
# def get_report_year_balance(self, obj, *args, **kwargs):
# ## this is actually being calculated on the frontend and not used
# kwargs = self.context.get('kwargs')
# report_id = int(kwargs.get('id'))
# report_year = self.retrieve_year(report_id)

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}
# 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')
Expand Down
25 changes: 25 additions & 0 deletions backend/api/services/model_year_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
ModelYearReportPreviousSales
from api.models.model_year_report_compliance_obligation import \
ModelYearReportComplianceObligation
from api.models.user_profile import UserProfile

from api.serializers.model_year_report_confirmation import \
ModelYearReportConfirmationSerializer
from api.serializers.user import MemberSerializer


def get_model_year_report_statuses(report):
Expand All @@ -16,6 +19,8 @@ def get_model_year_report_statuses(report):
supplier_information_confirmed_by = None
consumer_sales_confirmed_by = None
compliance_obligation_confirmed_by = None
summary_status = 'UNSAVED'
summary_confirmed_by = None

confirmations = ModelYearReportConfirmation.objects.filter(
model_year_report_id=report.id,
Expand Down Expand Up @@ -65,10 +70,26 @@ def get_model_year_report_statuses(report):
compliance_obligation_status = 'CONFIRMED'
compliance_obligation_confirmed_by = serializer.data

if supplier_information_status == 'CONFIRMED' and \
consumer_sales_status == 'CONFIRMED' and \
compliance_obligation_status == 'CONFIRMED':
summary_status = 'SAVED'

if report.validation_status == ModelYearReportStatuses.SUBMITTED:
supplier_information_status = 'SUBMITTED'
consumer_sales_status = 'SUBMITTED'
compliance_obligation_status = 'SUBMITTED'
summary_status = 'SUBMITTED'

user_profile = UserProfile.objects.filter(username=report.update_user)

if user_profile.exists():
serializer = MemberSerializer(user_profile.first(), read_only=True)

summary_confirmed_by = {
'create_timestamp': report.update_timestamp,
'create_user': serializer.data
}

return {
'supplier_information': {
Expand All @@ -82,5 +103,9 @@ def get_model_year_report_statuses(report):
'compliance_obligation': {
'status': compliance_obligation_status,
'confirmed_by': compliance_obligation_confirmed_by
},
'report_summary': {
'status': summary_status,
'confirmed_by': summary_confirmed_by
}
}
7 changes: 3 additions & 4 deletions backend/api/services/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@ def parse_summary_serializer(lst, serializer_data, category):
model_year = serializer_data['model_year'].get('name')
credit_class = serializer_data['credit_class'].get('credit_class')
total_value = serializer_data.get('total_value')

for data in lst:
index += 1

if data.get('model_year') == model_year and \
data.get('category') == category:
found = True
if credit_class == 'A':
lst[index].credit_a_value = total_value
lst[index]['credit_a_value'] = total_value
elif credit_class == 'B':
lst[index].credit_b_value = total_value
lst[index]['credit_b_value'] = total_value

if not found:
lst.append({
'credit_a_value': total_value if credit_class == 'A' else 0,
'credit_b_value': total_value if credit_class == 'B' else 0,
'category': category,
'model_year': model_year
'model_year': {'name': model_year}
})


Expand Down
22 changes: 22 additions & 0 deletions backend/api/viewsets/model_year_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,22 @@ def retrieve(self, request, pk=None):

return Response(serializer.data)

@action(detail=True)
def submission_confirmation(self, request, pk=None):
confirmation = ModelYearReportConfirmation.objects.filter(
model_year_report_id=pk,
signing_authority_assertion__module="compliance_summary"
).values_list(
'signing_authority_assertion_id', flat=True
)

return Response({'confirmation': confirmation})

@action(detail=False, methods=['patch'])
def submission(self, request):
validation_status = request.data.get('validation_status')
model_year_report_id = request.data.get('model_year_report_id')
confirmations = request.data.get('confirmation')

model_year_report_update = ModelYearReport.objects.filter(
id=model_year_report_id
Expand All @@ -146,6 +158,16 @@ def submission(self, request):
create_user=request.user.username,
)

for confirmation in confirmations:
summary_confirmation = ModelYearReportConfirmation.objects.create(
create_user=request.user.username,
model_year_report_id=model_year_report_id,
has_accepted=True,
title=request.user.title,
signing_authority_assertion_id=confirmation
)
summary_confirmation.save()

return HttpResponse(
status=201, content="Report Submitted"
)
30 changes: 20 additions & 10 deletions backend/api/viewsets/model_year_report_compliance_obligation.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,17 @@ def details(self, request, *args, **kwargs):
snapshot = ModelYearReportComplianceObligation.objects.filter(
model_year_report_id=report.id,
).order_by('-update_timestamp')
if confirmation and snapshot:
offset_snapshot = ModelYearReportCreditOffset.objects.filter(
model_year_report_id=report.id,
).order_by('-update_timestamp')
offset_snapshot = ModelYearReportCreditOffset.objects.filter(
model_year_report_id=report.id,
).order_by('-update_timestamp')
compliance_offset = None
if offset_snapshot:
offset_serializer = ModelYearReportComplianceObligationOffsetSerializer(
offset_snapshot, context={'request': request, 'kwargs': kwargs}, many=True
)
compliance_offset = offset_serializer.data

if confirmation and snapshot:
serializer = ModelYearReportComplianceObligationSnapshotSerializer(
snapshot, context={'request': request, 'kwargs': kwargs}, many=True
)
Expand Down Expand Up @@ -190,7 +194,7 @@ def details(self, request, *args, **kwargs):
parse_summary_serializer(content, transfer_out, 'transfersOut')

for credits_sale in credit_sales_serializer.data:
parse_summary_serializer(content, credits_sale, 'creditsSale')
parse_summary_serializer(content, credits_sale, 'creditsIssuedSales')

pending_sales_submissions = SalesSubmission.objects.filter(
organization=request.user.organization,
Expand Down Expand Up @@ -222,7 +226,7 @@ def details(self, request, *args, **kwargs):
'credit_a_value': totals[key].get('A'),
'credit_b_value': totals[key].get('B'),
'category': 'pendingBalance',
'model_year': key
'model_year': {'name': key}
})

prior_year = report_year-1
Expand All @@ -232,7 +236,7 @@ def details(self, request, *args, **kwargs):
'credit_a_value': prior_year_balance_a,
'credit_b_value': prior_year_balance_b,
'category': 'creditBalanceStart',
'model_year': report_year_obj.name
'model_year': {'name': report_year_obj.name}
})

report_year_balance_a = retrieve_balance(organization.id, report_year, 'A')
Expand All @@ -241,9 +245,15 @@ def details(self, request, *args, **kwargs):
'credit_a_value': report_year_balance_a,
'credit_b_value': report_year_balance_b,
'category': 'creditBalanceEnd',
'model_year': report_year_obj.name
'model_year': {'name': report_year_obj.name}
})

return Response(content)
return Response({
'compliance_obligation': content,
'compliance_offset': compliance_offset
})

return Response(serializer.data)
return Response({
'compliance_obligation': serializer.data,
'compliance_offset': compliance_offset
})
48 changes: 44 additions & 4 deletions backend/api/viewsets/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from rest_framework import mixins, viewsets
from rest_framework.decorators import action
from rest_framework.response import Response
import datetime

from django.db.models import Q
import xlrd
from api.models.sales_submission import SalesSubmission

from api.decorators.permission import permission_required
from api.models.vehicle_class import VehicleClass
Expand All @@ -18,6 +23,7 @@
VehicleStatusChangeSerializer, VehicleIsActiveChangeSerializer, \
VehicleSalesSerializer
from api.services.minio import minio_put_object
from api.models.sales_submission_content import SalesSubmissionContent
from auditable.views import AuditableMixin


Expand Down Expand Up @@ -96,9 +102,43 @@ def classes(self, _request):
serializer = VehicleClassSerializer(classes, many=True)
return Response(serializer.data)

@action(detail=False)
def vehicles_sales(self, _request):
vehicles = self.get_queryset()
@action(detail=True)
def vehicles_sales(self, _request, *args, **kwargs):
report_year = int(kwargs.pop('pk'))
organization_id = _request.user.organization.id
org_submission = SalesSubmission.objects.filter(
organization_id=organization_id)
from_date = (report_year-1, 10, 1,)
to_date = (report_year, 9, 30,)

sales_from_date = xlrd.xldate.xldate_from_date_tuple(from_date, 0)
sales_to_date = xlrd.xldate.xldate_from_date_tuple(to_date, 0)
sales = SalesSubmissionContent.objects.values(
'xls_make', 'xls_model', 'xls_model_year'
).filter(
Q(Q(
Q(xls_sale_date__lte=sales_to_date) &
Q(xls_sale_date__gte=sales_from_date) &
Q(xls_date_type="3") &
~Q(xls_sale_date="")
) |
Q(
Q(xls_sale_date__lte=str(report_year) + "-09-30") &
Q(xls_sale_date__gte=str(report_year-1) + "-10-01") &
Q(xls_date_type="1") &
~Q(xls_sale_date="")
)
)
).filter(submission__in=org_submission)

vehicles = Vehicle.objects.none()
for sale in sales:
model_year = ModelYear.objects.get(name=sale['xls_model_year'][0:4])
vehicles |= Vehicle.objects.filter(
make=sale['xls_make'],
model_name=sale['xls_model'],
model_year=model_year)

serializer = VehicleSalesSerializer(vehicles, many=True)
return Response(serializer.data)

Expand All @@ -107,7 +147,7 @@ def years(self, _request):
"""
Get the years
"""
exclude_years = ['2017','2018']
exclude_years = ['2017', '2018']
years = ModelYear.objects.all().order_by('-name').exclude(name__in=exclude_years)
serializer = ModelYearSerializer(years, many=True)
return Response(serializer.data)
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zeva-frontend",
"version": "1.24.0-1",
"version": "1.25.0",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-free": "^5.13.0",
Expand Down
Loading

0 comments on commit d25511f

Please sign in to comment.