From b0e35d35fff1ea9ef26906821add38303c22d29d Mon Sep 17 00:00:00 2001 From: emi-hi Date: Wed, 26 May 2021 14:04:13 -0700 Subject: [PATCH 1/5] -linting --- .../src/compliance/ConsumerSalesContainer.js | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/frontend/src/compliance/ConsumerSalesContainer.js b/frontend/src/compliance/ConsumerSalesContainer.js index 4a93f52ee..8ac469478 100644 --- a/frontend/src/compliance/ConsumerSalesContainer.js +++ b/frontend/src/compliance/ConsumerSalesContainer.js @@ -40,7 +40,6 @@ const ConsumerSalesContainer = (props) => { validationStatus, } = consumerSalesResponse.data; - if (vehicleList.length > 0) { setVehicles(vehicleList); } @@ -94,7 +93,7 @@ const ConsumerSalesContainer = (props) => { const handleCheckboxClick = (event) => { if (!event.target.checked) { const checked = checkboxes.filter( - (each) => Number(each) !== Number(event.target.id) + (each) => Number(each) !== Number(event.target.id), ); setCheckboxes(checked); } @@ -106,21 +105,20 @@ const ConsumerSalesContainer = (props) => { }; const handleSave = () => { - axios.post(ROUTES_COMPLIANCE.CONSUMER_SALES, { - data: vehicles, - modelYearReportId: id, - confirmation: checkboxes, - }).then(() => { - history.push(ROUTES_COMPLIANCE.REPORTS); - history.replace(ROUTES_COMPLIANCE.REPORT_CONSUMER_SALES.replace(':id', id)); - }).catch((error) => { - const { response } = error; - if (response.status === 400) { - setErrorMessage(error.response.data.status); - } - }); - } - + axios.post(ROUTES_COMPLIANCE.CONSUMER_SALES, { + data: vehicles, + modelYearReportId: id, + confirmation: checkboxes, + }).then(() => { + history.push(ROUTES_COMPLIANCE.REPORTS); + history.replace(ROUTES_COMPLIANCE.REPORT_CONSUMER_SALES.replace(':id', id)); + }).catch((error) => { + const { response } = error; + if (response.status === 400) { + setErrorMessage(error.response.data.status); + } + }); + }; useEffect(() => { refreshDetails(true); From 94a8dab4519205b41e0d19ab9979e88e115b4e2d Mon Sep 17 00:00:00 2001 From: emi-hi Date: Wed, 26 May 2021 15:19:18 -0700 Subject: [PATCH 2/5] adds areas for supplier class and 3 year ldv sales --- .../SupplierInformationDetailsPage.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/frontend/src/compliance/components/SupplierInformationDetailsPage.js b/frontend/src/compliance/components/SupplierInformationDetailsPage.js index 6f58227d3..01f743ec8 100644 --- a/frontend/src/compliance/components/SupplierInformationDetailsPage.js +++ b/frontend/src/compliance/components/SupplierInformationDetailsPage.js @@ -143,6 +143,24 @@ const SupplierInformationDetailsPage = (props) => { ) ))} +
+
+
+

Vehicle Supplier Class:

+ Volume Supplier () +
+
+

3 Year Average LDV Sales:

+ Volume Supplier () +
+
+
+
+ + sales/leases +
+
+
If there is an error in any of the information above, please contact: ZEVRegulation@gov.bc.ca
From 32a8516cfbdeb482a34cb8d55e964698162214da Mon Sep 17 00:00:00 2001 From: emi-hi Date: Wed, 26 May 2021 15:44:37 -0700 Subject: [PATCH 3/5] -adds state for average sales list, will add to backend later --- .../compliance/SupplierInformationContainer.js | 4 +++- .../SupplierInformationDetailsPage.js | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/frontend/src/compliance/SupplierInformationContainer.js b/frontend/src/compliance/SupplierInformationContainer.js index 01d233b4a..2f8b7aa94 100644 --- a/frontend/src/compliance/SupplierInformationContainer.js +++ b/frontend/src/compliance/SupplierInformationContainer.js @@ -22,6 +22,7 @@ const SupplierInformationContainer = (props) => { const [checkboxes, setCheckboxes] = useState([]); const [disabledCheckboxes, setDisabledCheckboxes] = useState(''); const [details, setDetails] = useState({}); + const [previousYearsList, setPreviousYearsList] = useState([{}]); const [modelYear, setModelYear] = useState(CONFIG.FEATURES.MODEL_YEAR_REPORT.DEFAULT_YEAR); const [statuses, setStatuses] = useState({ supplierInformation: { @@ -112,7 +113,7 @@ const SupplierInformationContainer = (props) => { confirmations, statuses: reportStatuses, } = response.data; - + setPreviousYearsList([{ id: 0, previousSales: 323, modelYear: 2020 }]); setModelYear(parseInt(reportModelYear.name, 10)); if (modelYearReportMakes) { @@ -194,6 +195,7 @@ const SupplierInformationContainer = (props) => { details={details} statuses={statuses} id={id} + previousYearsList={previousYearsList} /> ); diff --git a/frontend/src/compliance/components/SupplierInformationDetailsPage.js b/frontend/src/compliance/components/SupplierInformationDetailsPage.js index 01f743ec8..5a570e07d 100644 --- a/frontend/src/compliance/components/SupplierInformationDetailsPage.js +++ b/frontend/src/compliance/components/SupplierInformationDetailsPage.js @@ -31,6 +31,7 @@ const SupplierInformationDetailsPage = (props) => { modelYear, statuses, id, + previousYearsList, } = props; const [showModal, setShowModal] = useState(false); @@ -145,7 +146,7 @@ const SupplierInformationDetailsPage = (props) => {
-
+

Vehicle Supplier Class:

Volume Supplier ()
@@ -156,8 +157,19 @@ const SupplierInformationDetailsPage = (props) => {
- - sales/leases +
+ {previousYearsList.map((yearSale) => ( +
+ + +
+ ))} +
From a3ca081b6e27c88bdd0022e0c2a88af19290fd89 Mon Sep 17 00:00:00 2001 From: emi-hi Date: Thu, 27 May 2021 15:39:40 -0700 Subject: [PATCH 4/5] -adds ldv sales and supplier class to frontend (using data from report details) --- .../SupplierInformationContainer.js | 23 +++++++++++++++++- .../SupplierInformationDetailsPage.js | 24 ++++++++++++------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/frontend/src/compliance/SupplierInformationContainer.js b/frontend/src/compliance/SupplierInformationContainer.js index 2f8b7aa94..224aea0a3 100644 --- a/frontend/src/compliance/SupplierInformationContainer.js +++ b/frontend/src/compliance/SupplierInformationContainer.js @@ -104,6 +104,8 @@ const SupplierInformationContainer = (props) => { if (id && id !== 'new') { axios.get(ROUTES_COMPLIANCE.REPORT_DETAILS.replace(/:id/g, id)).then((response) => { const { + ldvSales, + supplierClass, makes: modelYearReportMakes, modelYearReportAddresses, modelYearReportHistory, @@ -121,9 +123,28 @@ const SupplierInformationContainer = (props) => { setMakes(currentMakes); } - + let supplierClassString = {}; + + if (supplierClass === 'L') { + supplierClassString = { + class: 'Large', + secondaryText: '(5,000 or more total LDV sales)', + }; + } else if (supplierClass === 'M') { + supplierClassString = { + class: 'Medium', + secondaryText: '(1,000 to 4,999 total LDV sales)', + }; + } else if (supplierClass === 'S') { + supplierClassString = { + class: 'Small', + secondaryText: '(less than 1,000 total LDV sales)', + }; + } setDetails({ organization: { + ldvSales, + supplierClassString, name: organizationName, organizationAddress: modelYearReportAddresses, }, diff --git a/frontend/src/compliance/components/SupplierInformationDetailsPage.js b/frontend/src/compliance/components/SupplierInformationDetailsPage.js index 5a570e07d..49b468b31 100644 --- a/frontend/src/compliance/components/SupplierInformationDetailsPage.js +++ b/frontend/src/compliance/components/SupplierInformationDetailsPage.js @@ -145,17 +145,25 @@ const SupplierInformationDetailsPage = (props) => { ))}
-
-
-

Vehicle Supplier Class:

- Volume Supplier () +
+
+ +

Vehicle Supplier Class:

+
+ + {details.organization.supplierClassString.class} Volume Supplier +
+ {details.organization.supplierClassString.secondaryText} +
-
-

3 Year Average LDV Sales:

- Volume Supplier () +
+ +

3 Year Average LDV Sales:

+
+ {details.organization.ldvSales}
-
+
{previousYearsList.map((yearSale) => ( From 7c5ee3dbf14a155c21ff5fdfe2b35ccba81a173b Mon Sep 17 00:00:00 2001 From: emi-hi Date: Fri, 28 May 2021 13:22:00 -0700 Subject: [PATCH 5/5] -adds ability to save snapshot -adds ldv sales list to snapshot -when retrieving snapshot, shows list for ldv sales and calculates the average --- backend/api/serializers/model_year_report.py | 37 +++++++++++- .../model_year_report_ldv_sales.py | 4 +- .../model_year_report_consumer_sales.py | 3 +- .../SupplierInformationContainer.js | 56 +++++++++++-------- .../SupplierInformationDetailsPage.js | 21 +++---- 5 files changed, 82 insertions(+), 39 deletions(-) diff --git a/backend/api/serializers/model_year_report.py b/backend/api/serializers/model_year_report.py index 0283f2547..b0705e24f 100644 --- a/backend/api/serializers/model_year_report.py +++ b/backend/api/serializers/model_year_report.py @@ -11,6 +11,8 @@ from api.models.model_year_report_address import ModelYearReportAddress from api.models.model_year_report_make import ModelYearReportMake from api.models.model_year_report_statuses import ModelYearReportStatuses +from api.models.model_year_report_ldv_sales import ModelYearReportLDVSales +from api.serializers.model_year_report_ldv_sales import ModelYearReportLDVSalesSerializer from api.models.user_profile import UserProfile from api.serializers.model_year_report_address import \ ModelYearReportAddressSerializer @@ -22,6 +24,7 @@ from api.serializers.vehicle import ModelYearSerializer from api.services.model_year_report import get_model_year_report_statuses + class ModelYearReportSerializer(ModelSerializer): create_user = SerializerMethodField() model_year = ModelYearSerializer() @@ -31,7 +34,28 @@ class ModelYearReportSerializer(ModelSerializer): model_year_report_history = ModelYearReportHistorySerializer(many=True) confirmations = SerializerMethodField() statuses = SerializerMethodField() + ldv_sales_previous = SerializerMethodField() + avg_sales = SerializerMethodField() + + def get_ldv_sales_previous(self, obj): + ldv_sales = ModelYearReportLDVSales.objects.filter( + model_year_report=obj + ) + serializer = ModelYearReportLDVSalesSerializer(ldv_sales, many=True) + return serializer.data + def get_avg_sales(self, obj): + rows = ModelYearReportLDVSales.objects.filter( + model_year_report_id=obj.id + ).values_list( + 'ldv_sales', flat=True + )[:3] + + avg_sales = 0 + if rows.count() < 3: + return None + avg_sales = sum(list(rows)) / 3 + return avg_sales def get_create_user(self, obj): user_profile = UserProfile.objects.filter(username=obj.create_user) @@ -71,10 +95,10 @@ def get_statuses(self, obj): class Meta: model = ModelYearReport fields = ( - 'organization_name', 'supplier_class', 'ldv_sales', 'model_year', + 'organization_name', 'supplier_class', 'model_year', 'model_year_report_addresses', 'makes', 'validation_status', 'create_user', 'model_year_report_history', 'confirmations', - 'statuses' + 'statuses', 'ldv_sales_previous', 'avg_sales' ) @@ -136,6 +160,7 @@ def create(self, validated_data): makes = validated_data.pop('makes') model_year = validated_data.pop('model_year') confirmations = request.data.get('confirmations') + ldv_sales = request.user.organization.ldv_sales report = ModelYearReport.objects.create( model_year_id=model_year.id, @@ -144,8 +169,14 @@ def create(self, validated_data): **validated_data, create_user=request.user.username, update_user=request.user.username, + supplier_class=request.user.organization.supplier_class ) - + for each in ldv_sales: + ModelYearReportLDVSales.objects.create( + model_year=each.model_year, + ldv_sales=each.ldv_sales, + model_year_report=report + ) for confirmation in confirmations: ModelYearReportConfirmation.objects.create( create_user=request.user.username, diff --git a/backend/api/serializers/model_year_report_ldv_sales.py b/backend/api/serializers/model_year_report_ldv_sales.py index 4aae24e99..06adddf90 100644 --- a/backend/api/serializers/model_year_report_ldv_sales.py +++ b/backend/api/serializers/model_year_report_ldv_sales.py @@ -1,5 +1,5 @@ from rest_framework.serializers import ModelSerializer, SlugRelatedField -from api.serializers.model_year_report import ModelYearReportSerializer +# from api.serializers.model_year_report import ModelYearReportSerializer from api.models.model_year import ModelYear from api.models.model_year_report_ldv_sales import \ @@ -11,7 +11,7 @@ class ModelYearReportLDVSalesSerializer(ModelSerializer): slug_field='name', queryset=ModelYear.objects.all() ) - model_year_report = ModelYearReportSerializer + # model_year_report = ModelYearReportSerializer class Meta: model = ModelYearReportLDVSales diff --git a/backend/api/viewsets/model_year_report_consumer_sales.py b/backend/api/viewsets/model_year_report_consumer_sales.py index 3459a9197..ef4350641 100644 --- a/backend/api/viewsets/model_year_report_consumer_sales.py +++ b/backend/api/viewsets/model_year_report_consumer_sales.py @@ -19,8 +19,7 @@ ModelYearReportHistorySerializer from api.serializers.model_year_report_vehicle import \ ModelYearReportVehicleSerializer, ModelYearReportVehicleSaveSerializer -from api.serializers.model_year_report_ldv_sales import \ - ModelYearReportLDVSalesSerializer + from api.serializers.model_year_report import ModelYearReportSerializer from api.serializers.vehicle import ModelYearSerializer from api.services.vehicle import vehicles_sales diff --git a/frontend/src/compliance/SupplierInformationContainer.js b/frontend/src/compliance/SupplierInformationContainer.js index 224aea0a3..15cea60a3 100644 --- a/frontend/src/compliance/SupplierInformationContainer.js +++ b/frontend/src/compliance/SupplierInformationContainer.js @@ -58,6 +58,9 @@ const SupplierInformationContainer = (props) => { event.preventDefault(); const data = { + class: user.organization.supplierClass, + averageLdvSales: details.organization.avgLdvSales, + previousLdvSales: details.organization.ldvSales, makes, modelYear, confirmations: checkboxes, @@ -88,6 +91,27 @@ const SupplierInformationContainer = (props) => { } }; + const getClassDescriptions = (supplierClass) => { + let supplierClassString = {}; + if (supplierClass === 'L') { + supplierClassString = { + class: 'Large', + secondaryText: '(5,000 or more total LDV sales)', + }; + } else if (supplierClass === 'M') { + supplierClassString = { + class: 'Medium', + secondaryText: '(1,000 to 4,999 total LDV sales)', + }; + } else if (supplierClass === 'S') { + supplierClassString = { + class: 'Small', + secondaryText: '(less than 1,000 total LDV sales)', + }; + } + return supplierClassString; + } + const handleCancelConfirmation = () => { const data = { delete_confirmations: true, @@ -104,7 +128,8 @@ const SupplierInformationContainer = (props) => { if (id && id !== 'new') { axios.get(ROUTES_COMPLIANCE.REPORT_DETAILS.replace(/:id/g, id)).then((response) => { const { - ldvSales, + avgSales, + ldvSalesPrevious, supplierClass, makes: modelYearReportMakes, modelYearReportAddresses, @@ -123,28 +148,13 @@ const SupplierInformationContainer = (props) => { setMakes(currentMakes); } - let supplierClassString = {}; - - if (supplierClass === 'L') { - supplierClassString = { - class: 'Large', - secondaryText: '(5,000 or more total LDV sales)', - }; - } else if (supplierClass === 'M') { - supplierClassString = { - class: 'Medium', - secondaryText: '(1,000 to 4,999 total LDV sales)', - }; - } else if (supplierClass === 'S') { - supplierClassString = { - class: 'Small', - secondaryText: '(less than 1,000 total LDV sales)', - }; - } + const supplierClassString = getClassDescriptions(supplierClass); + console.log(ldvSalesPrevious) setDetails({ + supplierClassString, organization: { - ldvSales, - supplierClassString, + avgLdvSales: avgSales, + ldvSales: ldvSalesPrevious, name: organizationName, organizationAddress: modelYearReportAddresses, }, @@ -162,9 +172,11 @@ const SupplierInformationContainer = (props) => { } else { axios.get(ROUTES_VEHICLES.LIST).then((response) => { const { data } = response; - + const previousSales = user.organization.ldvSales + const supplierClassString = getClassDescriptions(user.organization.supplierClass) setMakes([...new Set(data.map((vehicle) => vehicle.make.toUpperCase()))]); setDetails({ + supplierClassString, organization: user.organization, supplierInformation: { history: [], diff --git a/frontend/src/compliance/components/SupplierInformationDetailsPage.js b/frontend/src/compliance/components/SupplierInformationDetailsPage.js index 49b468b31..0689c399a 100644 --- a/frontend/src/compliance/components/SupplierInformationDetailsPage.js +++ b/frontend/src/compliance/components/SupplierInformationDetailsPage.js @@ -8,7 +8,7 @@ import Modal from '../../app/components/Modal'; import history from '../../app/History'; import CustomPropTypes from '../../app/utilities/props'; import ROUTES_COMPLIANCE from '../../app/routes/Compliance'; - +import FormatNumeric from '../../app/utilities/formatNumeric'; import ComplianceReportAlert from './ComplianceReportAlert'; import ComplianceReportSignOff from './ComplianceReportSignOff'; @@ -32,12 +32,11 @@ const SupplierInformationDetailsPage = (props) => { statuses, id, previousYearsList, + avgSales, } = props; - const [showModal, setShowModal] = useState(false); let disabledCheckboxes = propsDisabledCheckboxes; let disabledInputs = false; - if (loading) { return ; } @@ -151,33 +150,35 @@ const SupplierInformationDetailsPage = (props) => {

Vehicle Supplier Class:

- {details.organization.supplierClassString.class} Volume Supplier + {details.supplierClassString.class} Volume Supplier
- {details.organization.supplierClassString.secondaryText} + {details.supplierClassString.secondaryText}

3 Year Average LDV Sales:

- {details.organization.ldvSales} + {FormatNumeric(details.organization.avgLdvSales)}
-
+
+ {details.organization.ldvSales + && (
- {previousYearsList.map((yearSale) => ( + {details.organization.ldvSales.map((yearSale) => (
))}
+ )}