Skip to content

Commit

Permalink
Tracking pull request to merge the release-1.31.0 to master (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuanfandevops authored Oct 22, 2021
1 parent 8c4dbcd commit 716b272
Show file tree
Hide file tree
Showing 30 changed files with 616 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .pipeline/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const phases = {
purchaseRequestsEnabled: 'false',
notificationsEnabled: 'true',
rolesEnabled: 'false',
creditAgreementsEnabled: 'false',
creditAgreementsEnabled: 'true',
backendCpuRequest: '200m', backendCpuLimit: '700m', backendMemoryRequest: '1G', backendMemoryLimit: '2G', backendHealthCheckDelay: 30, backendReplicas: 2, backendMinReplicas: 2, backendMaxReplicas: 5, backendHost: `zeva-backend-prod.${ocpName}.gov.bc.ca`,
minioCpuRequest: '100m', minioCpuLimit: '300m', minioMemoryRequest: '500M', minioMemoryLimit: '700M', minioPvcSize: '3G',
schemaspyCpuRequest: '50m', schemaspyCpuLimit: '400m', schemaspyMemoryRequest: '150M', schemaspyMemoryLimit: '300M', schemaspyHealthCheckDelay: 160,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.12 on 2021-10-14 01:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0131_auto_20211001_1517'),
]

operations = [
migrations.AddField(
model_name='salessubmission',
name='part_of_model_year_report',
field=models.BooleanField(blank=True, default=False, null=True),
),
]
20 changes: 20 additions & 0 deletions backend/api/models/model_year_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from api.models.model_year_report_compliance_obligation import \
ModelYearReportComplianceObligation
from api.models.supplemental_report import SupplementalReport
from api.models.user_profile import UserProfile


class ModelYearReport(Auditable):
Expand Down Expand Up @@ -85,6 +86,25 @@ def supplemental(self):
return SupplementalReport.objects.filter(
model_year_report_id=self.id
).order_by('-update_timestamp').first()


def get_latest_supplemental(self, request):
reports = SupplementalReport.objects.filter(
model_year_report_id=self.id
).order_by('-update_timestamp')
for report in reports:
create_user = UserProfile.objects.get(
username=report.create_user)
if request.user.is_government:
if report.status.value in ['SUBMITTED','RECOMMENDED', 'ASSESSED', 'RETURNED']:
return report
if report.status.value == 'DRAFT' and create_user.is_government:
return report
if not request.user.is_government:
if report.status.value in ['SUBMITTED','ASSESSED']:
return report
if report.status.value == 'DRAFT' and not create_user.is_government:
return report

def get_supplemental(self, supplemental_id):
return SupplementalReport.objects.filter(
Expand Down
6 changes: 6 additions & 0 deletions backend/api/models/sales_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class SalesSubmission(Auditable):
statuses=[c.name for c in SalesSubmissionStatuses]
)
)
part_of_model_year_report = models.BooleanField(
default=False,
null=True,
blank=True,
db_comment="determine if issue as Sept 30 as part of model year report."
)
filename = models.CharField(
blank=True,
max_length=260,
Expand Down
85 changes: 84 additions & 1 deletion backend/api/serializers/model_year_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
from api.serializers.model_year_report_ldv_sales import ModelYearReportLDVSalesSerializer
from api.models.user_profile import UserProfile
from api.models.model_year_report_assessment import ModelYearReportAssessment
from api.models.supplemental_report import SupplementalReport
from api.serializers.model_year_report_address import \
ModelYearReportAddressSerializer

from api.serializers.model_year_report_make import \
ModelYearReportMakeSerializer
from api.serializers.model_year_report_history import \
Expand Down Expand Up @@ -209,8 +211,22 @@ class ModelYearReportListSerializer(
obligation_total = SerializerMethodField()
obligation_credits = SerializerMethodField()
ldv_sales = SerializerMethodField()
supplemental_status = SerializerMethodField()



def get_ldv_sales(self, obj):
request = self.context.get('request')

is_assessed = (
(request.user.organization_id == obj.organization_id and
obj.validation_status == ModelYearReportStatuses.ASSESSED) or
request.user.is_government
)

if is_assessed:
return obj.get_ldv_sales(from_gov=True) or obj.ldv_sales

return obj.ldv_sales

def get_compliant(self, obj):
Expand Down Expand Up @@ -247,12 +263,79 @@ def get_validation_status(self, obj):
return ModelYearReportStatuses.SUBMITTED.value
return obj.get_validation_status_display()

def get_supplemental_status(self, obj):
request = self.context.get('request')
supplemental_records = SupplementalReport.objects.filter(
model_year_report=obj
).order_by('-create_timestamp')
supplemental_record = 0
if supplemental_records:
supplemental_record = supplemental_records[0]
if supplemental_record:
# get information on who created the record
create_user = UserProfile.objects.get(
username=supplemental_record.create_user
)
sup_status = supplemental_record.status.value
if create_user.is_government:
if sup_status == 'RETURNED':
# this record was created by idir but
# should show up as supplementary returned
return ('SUPPLEMENTARY {}').format(sup_status)
if sup_status == 'REASSESSED' or sup_status == 'ASSESSED':
# bceid and idir can see just 'reassessed' as status
return 'REASSESSED'
if request.user.is_government and sup_status in ['DRAFT', 'RECOMMENDED']:
# created by idir and viewed by idir, they can see
# draft or recommended status
return ('REASSESSMENT {}').format(sup_status)
if not request.user.is_government and sup_status in ['SUBMITTED', 'DRAFT', 'RECOMMENDED']:
# if it is being viewed by bceid, they shouldnt see it
# unless it is reassessed or returned
if supplemental_records.count() > 1:
for each in supplemental_records:
# find the newest record that is either created by bceid or one that they are allowed to see
item_create_user = UserProfile.objects.get(username=each.create_user)
# bceid are allowed to see any created by them or
# if the status is REASSESSED or RETURNED?
if not item_create_user.is_government or each.status.value == 'RETURNED':
return ('SUPPLEMENTARY {}').format(each.status.value)
if each.status.value == 'REASSESSED':
return each.status.value
else:
# if created by bceid its a supplemental report
if sup_status == 'SUBMITTED':
return('SUPPLEMENTARY {}').format(sup_status)
if sup_status == 'DRAFT':
if not request.user.is_government:
return('SUPPLEMENTARY {}').format(sup_status)
else:
# same logic for bceid to check if theres another record
if supplemental_records.count() > 1:
for each in supplemental_records:
# find the newest record that is either
# created by bceid or they are able to see
item_create_user = UserProfile.objects.get(username=each.create_user)
# they are allowed to see any created by idir
# or if it is submitted
if item_create_user.is_government:
return ('REASSESSMENT {}').format(each.status.value)
if each.status.value == 'SUBMITTED':
return ('SUPPLEMENTARY {}').format(each.status.value)

# no supplemental report, just return the status from the assessment
if not request.user.is_government and obj.validation_status in [
ModelYearReportStatuses.RECOMMENDED,
ModelYearReportStatuses.RETURNED]:
return ModelYearReportStatuses.SUBMITTED.value
return obj.get_validation_status_display()

class Meta:
model = ModelYearReport
fields = (
'id', 'organization_name', 'model_year', 'validation_status', 'ldv_sales',
'supplier_class', 'compliant', 'obligation_total',
'obligation_credits',
'obligation_credits', 'supplemental_status'
)


Expand Down
15 changes: 14 additions & 1 deletion backend/api/serializers/model_year_report_noa.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Meta:
class SupplementalNOASerializer(ModelSerializer):
status = SerializerMethodField()
update_user = SerializerMethodField()
is_reassessment = SerializerMethodField()

def get_status(self, obj):
return obj.validation_status.value
Expand All @@ -38,8 +39,20 @@ def get_update_user(self, obj):
return obj.create_user
return user.display_name

def get_is_reassessment(self, obj):
user = UserProfile.objects.filter(username=obj.create_user).first()
if user is None:
return False

if user.is_government:
return True

return False


class Meta:
model = SupplementalReportHistory
fields = (
'update_timestamp', 'status', 'id', 'update_user', 'supplemental_report_id'
'update_timestamp', 'status', 'id', 'update_user', 'supplemental_report_id',
'is_reassessment'
)
28 changes: 22 additions & 6 deletions backend/api/serializers/model_year_report_supplemental.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,32 @@ class ModelYearReportSupplementalSerializer(ModelSerializer):
attachments = SerializerMethodField()
from_supplier_comments = SerializerMethodField()
actual_status = SerializerMethodField()
create_user = SerializerMethodField()

def get_create_user(self, obj):
user_profile = UserProfile.objects.filter(username=obj.create_user)
if user_profile.exists():
serializer = MemberSerializer(user_profile.first(), read_only=True)
return serializer.data
return obj.create_user

def get_actual_status(self, obj):
latest_report = SupplementalReport.objects.filter(
model_year_report_id=obj.model_year_report_id
request = self.context.get('request')
supplemental_report = SupplementalReport.objects.filter(
model_year_report_id=obj.model_year_report_id,
supplemental_id=obj.id
).order_by('-update_timestamp').first()

if not latest_report:
return None
if not supplemental_report:
return obj.status.value

if supplemental_report.status == ModelYearReportStatuses.RECOMMENDED:
return ModelYearReportStatuses.RECOMMENDED.value if request and request.user.is_government else obj.status.value

if supplemental_report.status == ModelYearReportStatuses.ASSESSED:
return ModelYearReportStatuses.ASSESSED.value

return latest_report.status.value
return supplemental_report.status.value

def get_from_supplier_comments(self, obj):
comments = SupplementalReportComment.objects.filter(
Expand Down Expand Up @@ -329,5 +345,5 @@ class Meta:
fields = (
'id', 'status', 'ldv_sales', 'credit_activity',
'assessment_data', 'zev_sales', 'supplier_information',
'attachments', 'from_supplier_comments', 'actual_status'
'attachments', 'from_supplier_comments', 'actual_status', 'create_user'
)
17 changes: 15 additions & 2 deletions backend/api/serializers/sales_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from api.models.record_of_sale_statuses import RecordOfSaleStatuses
from api.models.sales_submission import SalesSubmission
from api.models.sales_submission_content import SalesSubmissionContent
from api.models.credit_transaction import \
CreditTransaction
from api.models.sales_submission_statuses import SalesSubmissionStatuses
from api.models.sales_submission_comment import SalesSubmissionComment
from api.models.sales_submission_history import SalesSubmissionHistory
Expand Down Expand Up @@ -93,6 +95,15 @@ class SalesSubmissionListSerializer(

def get_submission_history(self, obj):
request = self.context.get('request')

if obj.part_of_model_year_report:
credit_transaction = CreditTransaction.objects.filter(
sales_submission_credit_transaction__sales_submission_id=obj.id
).first()

if credit_transaction:
return credit_transaction.transaction_timestamp.date()

if not request.user.is_government and obj.validation_status in [
SalesSubmissionStatuses.RECOMMEND_REJECTION,
SalesSubmissionStatuses.RECOMMEND_APPROVAL,
Expand Down Expand Up @@ -462,7 +473,7 @@ class Meta:
'submission_sequence', 'content', 'submission_id', 'history',
'sales_submission_comment', 'update_user', 'unselected',
'update_timestamp', 'create_user', 'filename', 'create_timestamp',
'eligible', 'icbc_current_to', 'evidence',
'eligible', 'icbc_current_to', 'evidence','part_of_model_year_report'
)


Expand Down Expand Up @@ -522,6 +533,7 @@ def update(self, instance, validated_data):
comment_type = request.data.get('comment_type', None)
reasons = request.data.get('reasons', [])
reset = request.data.get('reset', None)
issue_as_model_year_report = request.data.get('issue_as_model_year_report', None)

if instance.validation_status != SalesSubmissionStatuses.DRAFT and \
not request.user.is_government:
Expand Down Expand Up @@ -667,6 +679,7 @@ def update(self, instance, validated_data):
)
instance.validation_status = validation_status
instance.update_user = request.user.username
instance.part_of_model_year_report=issue_as_model_year_report
instance.save()

return instance
Expand All @@ -677,5 +690,5 @@ class Meta:
'id', 'organization', 'submission_date',
'submission_sequence', 'submission_id',
'validation_status', 'sales_submission_comment',
'sales_evidences'
'sales_evidences', 'part_of_model_year_report'
)
13 changes: 11 additions & 2 deletions backend/api/services/credit_transaction.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date
from datetime import date, datetime
from decimal import Decimal
from django.db.models import Case, Count, Sum, Value, F, Q, When, Max
from django.db.models.functions import Coalesce
Expand All @@ -19,6 +19,7 @@
from api.models.organization_deficits import OrganizationDeficits
from api.models.model_year_report import ModelYearReport
from api.models.model_year_report_statuses import ModelYearReportStatuses
from api.models.sales_submission import SalesSubmission

from api.services.credit_transfer import aggregate_credit_transfer_details

Expand Down Expand Up @@ -140,6 +141,10 @@ def adjust_deficits(organization):


def award_credits(submission):
part_of_model_year_report = SalesSubmission.objects.filter(
id=submission.id
).values_list('part_of_model_year_report', flat=True).first()
current_year = datetime.now().year
records = RecordOfSale.objects.filter(
submission_id=submission.id,
validation_status="VALIDATED",
Expand Down Expand Up @@ -170,9 +175,13 @@ def award_credits(submission):
transaction_type="Validation"
),
update_user=submission.update_user,
weight_class=weight_class
weight_class=weight_class,
)

if part_of_model_year_report and current_year:
credit_transaction.transaction_timestamp=date(current_year, 9, 30,)
credit_transaction.save()

SalesSubmissionCreditTransaction.objects.create(
sales_submission_id=submission.id,
credit_transaction_id=credit_transaction.id
Expand Down
13 changes: 13 additions & 0 deletions backend/api/services/model_year_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,24 @@ def adjust_credits(id, request):

credit_reductions = {}

from_gov = False

# are there overrides?
# if so, then we should only get the ones from
has_override = ModelYearReportComplianceObligation.objects.filter(
model_year_report_id=id,
from_gov=True
).first()

if has_override:
from_gov = True

# order by timestamp is important as this is a way for us to check if there are
# overrides
reductions = ModelYearReportComplianceObligation.objects.filter(
model_year_report_id=id,
category__in=['ClassAReduction', 'UnspecifiedClassCreditReduction'],
from_gov=from_gov,
).order_by('model_year__name', 'update_timestamp')

for reduction in reductions:
Expand Down
Loading

0 comments on commit 716b272

Please sign in to comment.