diff --git a/backend/api/serializers/model_year_report.py b/backend/api/serializers/model_year_report.py index 9ccebf2a4..100509728 100644 --- a/backend/api/serializers/model_year_report.py +++ b/backend/api/serializers/model_year_report.py @@ -223,6 +223,7 @@ class ModelYearReportListSerializer( obligation_credits = SerializerMethodField() ldv_sales = SerializerMethodField() supplemental_status = SerializerMethodField() + supplemental_id = SerializerMethodField() def get_ldv_sales(self, obj): request = self.context.get('request') @@ -336,13 +337,25 @@ def get_supplemental_status(self, obj): ModelYearReportStatuses.RETURNED]: return ModelYearReportStatuses.SUBMITTED.value return obj.get_validation_status_display() - + + def get_supplemental_id(self, obj): + request = self.context.get('request') + supplemental_records = SupplementalReport.objects.filter( + model_year_report=obj + ).order_by('-create_timestamp') + + if supplemental_records: + supplemental_record = supplemental_records[0] + return supplemental_record.id + + return None + class Meta: model = ModelYearReport fields = ( 'id', 'organization_name', 'model_year', 'validation_status', 'ldv_sales', 'supplier_class', 'compliant', 'obligation_total', - 'obligation_credits', 'supplemental_status' + 'obligation_credits', 'supplemental_status', 'supplemental_id' ) diff --git a/backend/api/viewsets/model_year_report.py b/backend/api/viewsets/model_year_report.py index ebf844466..4301c3da0 100644 --- a/backend/api/viewsets/model_year_report.py +++ b/backend/api/viewsets/model_year_report.py @@ -943,9 +943,10 @@ def supplemental_comment_save(self, request, pk): report = get_object_or_404(ModelYearReport, pk=pk) comment = request.data.get('from_govt_comment') director = request.data.get('director') + supplemental_id = request.data.get('supplemental_id', report.supplemental.id) if comment and director: SupplementalReportAssessmentComment.objects.create( - supplemental_report_id=report.supplemental.id, + supplemental_report_id=supplemental_id, comment=comment, to_director=True, create_user=request.user.username, @@ -953,7 +954,7 @@ def supplemental_comment_save(self, request, pk): ) elif comment and not director: assessment_comment = SupplementalReportAssessmentComment.objects.filter( - supplemental_report_id=report.supplemental.id, + supplemental_report_id=supplemental_id, to_director=False ).order_by('-update_timestamp').first() @@ -963,7 +964,7 @@ def supplemental_comment_save(self, request, pk): assessment_comment.save() else: SupplementalReportAssessmentComment.objects.create( - supplemental_report_id=report.supplemental.id, + supplemental_report_id=supplemental_id, to_director=False, comment=comment, create_user=request.user.username, diff --git a/frontend/src/app/components/Comment.js b/frontend/src/app/components/Comment.js index 37759899a..8fd3f7f1c 100644 --- a/frontend/src/app/components/Comment.js +++ b/frontend/src/app/components/Comment.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import moment from 'moment-timezone'; -//shows array of comments like +// shows array of comments like // Name, Date: Comment const Comment = (props) => { const { diff --git a/frontend/src/app/components/CommentInput.js b/frontend/src/app/components/CommentInput.js index e29a4d41e..9159af50d 100644 --- a/frontend/src/app/components/CommentInput.js +++ b/frontend/src/app/components/CommentInput.js @@ -38,8 +38,8 @@ const CommentInput = (props) => { {!disable && buttonText && ( <> - {tooltip !== '' && } - + {tooltip !== '' && buttonDisable && } +