Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTHUB-109: New Workflow for Reassessment #967

Merged
merged 15 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions backend/api/models/sales_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def next_sequence(org, date):

def validate_validation_status(self, status, request):
if self.validation_status in [
SalesSubmissionStatuses.VALIDATED,
SalesSubmissionStatuses.REJECTED
SalesSubmissionStatuses.VALIDATED
]:
raise ValidationError(
"Submission is already completed."
Expand Down
21 changes: 14 additions & 7 deletions backend/api/serializers/model_year_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ def get_model_year_report_history(self, obj):
]
)

# Remove submitted by government user (only happens when the IDIR user saves first)
users = UserProfile.objects.filter(organization__is_government=True).values_list('username')
history = history.exclude(
validation_status__in=[
ModelYearReportStatuses.SUBMITTED,
],
create_user__in=users
)

serializer = ModelYearReportHistorySerializer(history, many=True)

return serializer.data
Expand All @@ -189,6 +198,7 @@ class Meta:
'update_timestamp',
)


class ModelYearReportsSerializer(ModelSerializer):
validation_status = EnumField(ModelYearReportStatuses)
model_year = SlugRelatedField(
Expand All @@ -202,6 +212,7 @@ class Meta:
'organization_name', 'model_year', 'validation_status', 'id', 'organization_id'
)


class ModelYearReportListSerializer(
ModelSerializer, EnumSupportSerializerMixin
):
Expand All @@ -213,8 +224,6 @@ class ModelYearReportListSerializer(
ldv_sales = SerializerMethodField()
supplemental_status = SerializerMethodField()



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

Expand Down Expand Up @@ -291,17 +300,15 @@ def get_supplemental_status(self, obj):
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
# show the last assessed report
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':
# if the status is REASSESSED
if item_create_user.is_government and each.status.value == 'ASSESSED':
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':
Expand Down
36 changes: 33 additions & 3 deletions backend/api/serializers/model_year_report_noa.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def get_display_superseded_text(self, obj):
return True
return False


def get_is_reassessment(self, obj):
user = UserProfile.objects.filter(username=obj.create_user).first()
if user is None:
Expand All @@ -79,6 +78,14 @@ class Meta:
class SupplementalReportHistorySerializer(ModelSerializer):
status = SerializerMethodField()
create_user = SerializerMethodField()
is_reassessment = SerializerMethodField()

def get_is_reassessment(self, obj):
user = UserProfile.objects.filter(username=obj.create_user).first()
if user and user.is_government:
return True

return False

def get_status(self, obj):
return obj.validation_status.value
Expand All @@ -95,7 +102,7 @@ def get_create_user(self, obj):
class Meta:
model = SupplementalReportHistory
fields = (
'update_timestamp', 'status', 'create_user'
'update_timestamp', 'status', 'create_user', 'is_reassessment'
)


Expand Down Expand Up @@ -145,7 +152,12 @@ def get_history(self, obj):

if request.user.is_government:
filter_statuses.append(ModelYearReportStatuses.RECOMMENDED)

history = history.filter(
validation_status__in=[
ModelYearReportStatuses.SUBMITTED
]
)

reassessment_report = SupplementalReport.objects.filter(
supplemental_id=obj.id,
status__in=filter_statuses
Expand All @@ -167,6 +179,15 @@ def get_history(self, obj):
validation_status__in=filter_statuses
)

# Remove submitted by government user (only happens when the IDIR user saves first)
users = UserProfile.objects.filter(organization__is_government=True).values_list('username')
history = history.exclude(
validation_status__in=[
ModelYearReportStatuses.SUBMITTED,
],
create_user__in=users
)

serializer = SupplementalReportHistorySerializer(history, many=True)

return serializer.data
Expand Down Expand Up @@ -223,6 +244,15 @@ def get_history(self, obj):
]
)

# Remove submitted by government user (only happens when the IDIR user saves first)
users = UserProfile.objects.filter(organization__is_government=True).values_list('username')
history = history.exclude(
validation_status__in=[
ModelYearReportStatuses.SUBMITTED,
],
create_user__in=users
)

serializer = SupplementalReportHistorySerializer(history, many=True)

return serializer.data
Expand Down
79 changes: 78 additions & 1 deletion backend/api/serializers/model_year_report_supplemental.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,60 @@ class ModelYearReportSupplementalSerializer(ModelSerializer):
from_supplier_comments = SerializerMethodField()
actual_status = SerializerMethodField()
create_user = SerializerMethodField()
reassessment = SerializerMethodField()

def get_reassessment(self, obj):
user = UserProfile.objects.filter(username=obj.create_user).first()
if user and user.is_government:
supplementary_report = SupplementalReport.objects.filter(
model_year_report_id=obj.model_year_report_id,
supplemental_id=obj.supplemental_id
).first()

supplemental_user = None

if supplementary_report.create_user:
supplemental_user = UserProfile.objects.filter(username=supplementary_report.create_user).first()

supplementary_report_id = None
supplementary_report_status = supplementary_report.status.value
supplementary_report_is_reassessment = False
if supplemental_user:
supplementary_report_id = obj.supplemental_id
supplemental_report = SupplementalReport.objects.filter(
model_year_report_id=obj.model_year_report_id,
id=obj.supplemental_id
).first()

supplementary_report_status = supplemental_report.status.value

supplemental_user = UserProfile.objects.filter(username=supplemental_report.create_user).first()

if supplemental_user.is_government:
supplementary_report_is_reassessment = True

return {
'is_reassessment': True,
'supplementary_report_id': supplementary_report_id,
'status': supplementary_report_status,
'supplementary_report_is_reassessment': supplementary_report_is_reassessment
}

reassessment_report = SupplementalReport.objects.filter(
model_year_report_id=obj.model_year_report_id,
supplemental_id=obj.id
).first()

reassessment_report_id = None

if reassessment_report:
reassessment_report_id = reassessment_report.id

return {
'is_reassessment': False,
'reassessment_report_id': reassessment_report_id,
'status': obj.status.value
}

def get_create_user(self, obj):
user_profile = UserProfile.objects.filter(username=obj.create_user)
Expand All @@ -232,6 +286,12 @@ def get_create_user(self, obj):

def get_actual_status(self, obj):
request = self.context.get('request')
# is this a reassessment report? if so this is the actual status
create_user = UserProfile.objects.filter(username=obj.create_user).first()

if create_user and create_user.is_government:
return obj.status.value

supplemental_report = SupplementalReport.objects.filter(
model_year_report_id=obj.model_year_report_id,
supplemental_id=obj.id
Expand All @@ -240,6 +300,16 @@ def get_actual_status(self, obj):
if not supplemental_report:
return obj.status.value

if supplemental_report:
user = UserProfile.objects.filter(username=supplemental_report.create_user).first()

if user and user.is_government and not request.user.is_government and \
supplemental_report.status.value in ['ASSESSED', 'REASSESSED']:
return supplemental_report.status.value

if user and user.is_government and request.user.is_government:
return supplemental_report.status.value

model_year_report = ModelYearReport.objects.get(id=obj.model_year_report_id)
latest_supplemental = model_year_report.get_latest_supplemental(request)

Expand Down Expand Up @@ -284,6 +354,12 @@ def get_zev_sales(self, obj):
sales_queryset = SupplementalReportSales.objects.filter(
supplemental_report_id=obj.id
)

if not sales_queryset:
sales_queryset = SupplementalReportSales.objects.filter(
supplemental_report_id=obj.supplemental_id
)

sales_serializer = ModelYearReportZevSalesSerializer(sales_queryset, many=True)

return sales_serializer.data
Expand Down Expand Up @@ -345,5 +421,6 @@ class Meta:
fields = (
'id', 'status', 'ldv_sales', 'credit_activity',
'assessment_data', 'zev_sales', 'supplier_information',
'attachments', 'from_supplier_comments', 'actual_status', 'create_user'
'attachments', 'from_supplier_comments', 'actual_status',
'create_user', 'reassessment',
)
4 changes: 2 additions & 2 deletions backend/api/serializers/sales_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ def update(self, instance, validated_data):
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:
if instance.validation_status not in [SalesSubmissionStatuses.DRAFT, SalesSubmissionStatuses.REJECTED] \
and not request.user.is_government:
raise ValidationError(
"Submission cannot be modified when they've been submitted"
)
Expand Down
Loading