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 all 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
12 changes: 5 additions & 7 deletions backend/api/serializers/model_year_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class Meta:
'update_timestamp',
)


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


class ModelYearReportListSerializer(
ModelSerializer, EnumSupportSerializerMixin
):
Expand All @@ -222,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 @@ -300,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
1 change: 0 additions & 1 deletion 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 Down
8 changes: 8 additions & 0 deletions backend/api/serializers/model_year_report_supplemental.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,26 @@ def get_reassessment(self, obj):

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(
Expand Down
28 changes: 28 additions & 0 deletions backend/api/viewsets/model_year_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,34 @@ def supplemental_assessment(self, request, pk):
if not supplemental_id:
supplemental_id = report.supplemental.id

# check if we have permission for this
supplemental_report = SupplementalReport.objects.filter(
id=supplemental_id
).first()

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

if supplemental_report and request.user.is_government:
if supplemental_report.status.value == 'DRAFT' and not create_user.is_government:
supplemental_id = 0

if supplemental_report.status.value in [
'RETURNED',
'DELETED'
]:
supplemental_id = 0
elif supplemental_report and not request.user.is_government:
if supplemental_report.status.value == 'DRAFT' and create_user.is_government:
supplemental_id = 0

if supplemental_report.status.value in [
'RECOMMENDED',
'DELETED'
]:
supplemental_id = 0

serializer = SupplementalReportAssessmentSerializer(
supplemental_id, context={'request': request}
)
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/css/Supplementary.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
.nav-item {
padding: 1rem 0;

&.DRAFT, &.SUBMITTED, &.UNSAVED, &.SAVED {
&.DRAFT, &.UNSAVED, &.SAVED {
a {
border-bottom-color: $background-warning;
}
Expand All @@ -107,7 +107,7 @@
}
}

&.CONFIRMED, &.RECOMMENDED, &.RETURNED {
&.CONFIRMED, &.SUBMITTED, &.RECOMMENDED, &.RETURNED {
a {
border-bottom-color: $background-light-blue;
}
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/compliance/components/AssessmentDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ const AssessmentDetailsPage = (props) => {
<div className="col-12">
<div id="compliance-obligation-page">
{CONFIG.FEATURES.SUPPLEMENTAL_REPORT.ENABLED
&& !user.isGovernment && statuses.assessment.status === 'ASSESSED'
&& ((!supplementaryId && supplementaryStatus == 'DRAFT')
|| (supplementaryStatus == 'DRAFT' && createdByGov)
|| (supplementaryStatus == 'DELETED' || supplementaryStatus == 'ASSESSED')) && (
&& !user.isGovernment && statuses.assessment.status === 'ASSESSED'
&& ((!supplementaryId && supplementaryStatus === 'DRAFT')
|| (supplementaryStatus === 'DRAFT' && createdByGov)
|| (supplementaryStatus === 'DELETED' || supplementaryStatus === 'ASSESSED')) && (
<button
className="btn button primary float-right"
onClick={() => {
history.push(ROUTES_SUPPLEMENTARY.CREATE.replace(/:id/g, id), { new: true });
history.push(`${ROUTES_SUPPLEMENTARY.CREATE.replace(/:id/g, id)}?new=Y`);
}}
type="button"
>
Expand All @@ -223,13 +223,13 @@ const AssessmentDetailsPage = (props) => {
)}
{CONFIG.FEATURES.SUPPLEMENTAL_REPORT.ENABLED
&& user.isGovernment && user.hasPermission('RECOMMEND_COMPLIANCE_REPORT') && statuses.assessment.status === 'ASSESSED'
&& ((!supplementaryId && supplementaryStatus == 'DRAFT')
|| (supplementaryStatus == 'DRAFT' && !createdByGov)
|| (supplementaryStatus == 'DELETED' || supplementaryStatus == 'ASSESSED')) && (
&& ((!supplementaryId && supplementaryStatus === 'DRAFT')
|| (supplementaryStatus === 'DRAFT' && !createdByGov)
|| (supplementaryStatus === 'DELETED' || supplementaryStatus === 'ASSESSED')) && (
<button
className="btn button primary float-right"
onClick={() => {
history.push(ROUTES_SUPPLEMENTARY.REASSESSMENT.replace(/:id/g, id), { new: true });
history.push(`${ROUTES_SUPPLEMENTARY.REASSESSMENT.replace(/:id/g, id)}?new=Y`);
}}
type="button"
>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/compliance/components/ComplianceHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const ComplianceHistory = (props) => {
classname = 'alert-warning';
break;
case 'SUBMITTED':
classname = 'alert-warning';
classname = 'alert-primary';
break;
case 'RECOMMENDED':
classname = 'alert-primary';
Expand Down
34 changes: 20 additions & 14 deletions frontend/src/supplementary/SupplementaryContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import ROUTES_COMPLIANCE from '../app/routes/Compliance';
import history from '../app/History';
import CustomPropTypes from '../app/utilities/props';

const qs = require('qs');

const SupplementaryContainer = (props) => {
const { id, supplementaryId } = useParams();
const [checkboxConfirmed, setCheckboxConfirmed] = useState(false);
const [details, setDetails] = useState({});
const [loading, setLoading] = useState(true);
const [comment, setComment] = useState('');
const [salesRows, setSalesRows] = useState([]);
const { keycloak, user, reassessment } = props;
const { keycloak, user } = props;
const [files, setFiles] = useState([]);
const [deleteFiles, setDeleteFiles] = useState([]);
const [errorMessage, setErrorMessage] = useState(null);
Expand All @@ -33,6 +35,11 @@ const SupplementaryContainer = (props) => {
const [newReport, setNewReport] = useState(false);
const location = useLocation();

<<<<<<< HEAD
const query = qs.parse(location.search, { ignoreQueryPrefix: true });

=======
>>>>>>> upstream/release-1.35.0
const getNumeric = (parmValue) => {
let value = parmValue;

Expand All @@ -50,7 +57,6 @@ const SupplementaryContainer = (props) => {
const directorAction = user.isGovernment
&& user.hasPermission('SIGN_COMPLIANCE_REPORT');

const isReassessment = reassessment && user.isGovernment && user.hasPermission('RECOMMEND_COMPLIANCE_REPORT');
const calculateBalance = (creditActivity) => {
const balances = {};

Expand Down Expand Up @@ -239,7 +245,7 @@ const SupplementaryContainer = (props) => {
};

const handleSubmit = (status, paramNewReport) => {
if ((status == 'ASSESSED' && paramNewReport) || (status == 'SUBMITTED' && analystAction)) {
if ((status === 'ASSESSED' && paramNewReport) || (status === 'SUBMITTED' && analystAction)) {
status = 'DRAFT';
}
const uploadPromises = handleUpload(id);
Expand Down Expand Up @@ -327,7 +333,7 @@ const SupplementaryContainer = (props) => {
axios.get(`${ROUTES_SUPPLEMENTARY.ASSESSMENT.replace(':id', id)}?supplemental_id=${supplementaryId || ''}`),
]).then(axios.spread((response, complianceResponse, ratioResponse, assessmentResponse) => {
if (response.data) {
if (location && location.state && location.state.new) {
if (query && query.new === 'Y') {
setNewReport(true);
} else {
setNewReport(false);
Expand Down Expand Up @@ -471,19 +477,19 @@ const SupplementaryContainer = (props) => {
return (
<SupplementaryDetailsPage
addSalesRow={addSalesRow}
analystAction={analystAction}
checkboxConfirmed={checkboxConfirmed}
commentArray={commentArray}
analystAction={analystAction}
directorAction={directorAction}
deleteFiles={deleteFiles}
details={details}
directorAction={directorAction}
errorMessage={errorMessage}
files={files}
handleCheckboxClick={handleCheckboxClick}
handleAddIdirComment={handleAddIdirComment}
handleCommentChangeIdir={handleCommentChangeIdir}
handleCommentChangeBceid={handleCommentChangeBceid}
handleCheckboxClick={handleCheckboxClick}
handleCommentChange={handleCommentChange}
handleCommentChangeBceid={handleCommentChangeBceid}
handleCommentChangeIdir={handleCommentChangeIdir}
handleInputChange={handleInputChange}
handleSubmit={handleSubmit}
handleSupplementalChange={handleSupplementalChange}
Expand All @@ -492,17 +498,17 @@ const SupplementaryContainer = (props) => {
loading={loading}
newBalances={newBalances}
newData={newData}
newReport={newReport}
obligationDetails={obligationDetails}
query={query}
radioDescriptions={radioDescriptions}
ratios={ratios}
salesRows={salesRows}
setDeleteFiles={setDeleteFiles}
setUploadFiles={setFiles}
radioDescriptions={radioDescriptions}
user={user}
isReassessment={isReassessment}
setSupplementaryAssessmentData={setSupplementaryAssessmentData}
setUploadFiles={setFiles}
supplementaryAssessmentData={supplementaryAssessmentData}
newReport={newReport}
user={user}
/>
);
};
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/supplementary/components/CreditActivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ const CreditActivity = (props) => {
name="supplierInfo"
type="text"
onChange={handleInputChange}
defaultValue={newLdvSales ? newLdvSales : ldvSales}
defaultValue={newLdvSales || ldvSales}
readOnly={!isEditable}
/>
</td>
Expand Down Expand Up @@ -544,6 +544,7 @@ const CreditActivity = (props) => {

CreditActivity.defaultProps = {
creditReductionSelection: '',
isEditable: false,
newLdvSales: null,
supplierClass: '',
};
Expand All @@ -553,6 +554,7 @@ CreditActivity.propTypes = {
details: PropTypes.shape().isRequired,
handleInputChange: PropTypes.func.isRequired,
handleSupplementalChange: PropTypes.func.isRequired,
isEditable: PropTypes.bool,
ldvSales: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
Expand Down
Loading