From ac1bc2d63f3ce75d51df23b7601d074002c0ae24 Mon Sep 17 00:00:00 2001 From: Daniel Haselhan Date: Tue, 17 Dec 2024 14:50:59 -0800 Subject: [PATCH 1/5] fix: Sorting & Display of FSE * Sort both paginated and non paginated by create date asc to match other schedules * Fix kWH usage column to use nice number formatter without decimals --- backend/lcfs/web/api/final_supply_equipment/repo.py | 6 +++--- .../FinalSupplyEquipments/FinalSupplyEquipmentSummary.jsx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/lcfs/web/api/final_supply_equipment/repo.py b/backend/lcfs/web/api/final_supply_equipment/repo.py index b3680584f..f2353b624 100644 --- a/backend/lcfs/web/api/final_supply_equipment/repo.py +++ b/backend/lcfs/web/api/final_supply_equipment/repo.py @@ -201,7 +201,7 @@ async def get_fse_list(self, report_id: int) -> List[FinalSupplyEquipment]: joinedload(FinalSupplyEquipment.level_of_equipment), ) .where(FinalSupplyEquipment.compliance_report_id == report_id) - .order_by(FinalSupplyEquipment.final_supply_equipment_id) + .order_by(FinalSupplyEquipment.create_date.asc()) ) return result.unique().scalars().all() @@ -232,7 +232,7 @@ async def get_fse_paginated( result = await self.db.execute( query.offset(offset) .limit(limit) - .order_by(FinalSupplyEquipment.create_date.desc()) + .order_by(FinalSupplyEquipment.create_date.asc()) ) final_supply_equipments = result.unique().scalars().all() return final_supply_equipments, total_count @@ -356,7 +356,7 @@ async def increment_seq_by_org_and_postal_code( sequence_number = 1 return sequence_number - + @repo_handler async def check_uniques_of_fse_row(self, row: FinalSupplyEquipmentCreateSchema) -> bool: """ diff --git a/frontend/src/views/FinalSupplyEquipments/FinalSupplyEquipmentSummary.jsx b/frontend/src/views/FinalSupplyEquipments/FinalSupplyEquipmentSummary.jsx index 4753dc1fc..1869f3c63 100644 --- a/frontend/src/views/FinalSupplyEquipments/FinalSupplyEquipmentSummary.jsx +++ b/frontend/src/views/FinalSupplyEquipments/FinalSupplyEquipmentSummary.jsx @@ -8,11 +8,12 @@ import { useEffect, useMemo, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { useLocation, useParams, useNavigate } from 'react-router-dom' import { v4 as uuid } from 'uuid' +import { numberFormatter } from '@/utils/formatters.js' export const FinalSupplyEquipmentSummary = ({ data }) => { const [alertMessage, setAlertMessage] = useState('') const [alertSeverity, setAlertSeverity] = useState('info') - const [gridKey, setGridKey] = useState(`final-supply-equipments-grid`) + const [gridKey, setGridKey] = useState('final-supply-equipments-grid') const { complianceReportId, compliancePeriod } = useParams() const gridRef = useRef() @@ -72,8 +73,7 @@ export const FinalSupplyEquipmentSummary = ({ data }) => { 'finalSupplyEquipment:finalSupplyEquipmentColLabels.kwhUsage' ), field: 'kwhUsage', - valueFormatter: (params) => - params.value ? params.value.toFixed(2) : '0.00' + valueFormatter: numberFormatter }, { headerName: t( From 29c2bc84b02229467fc54e8e6bd2ecf3af1bec80 Mon Sep 17 00:00:00 2001 From: prv-proton Date: Tue, 17 Dec 2024 15:13:14 -0800 Subject: [PATCH 2/5] fix issue of updating gov users with "Government of B.C." in database. --- backend/lcfs/web/api/notification/schema.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/backend/lcfs/web/api/notification/schema.py b/backend/lcfs/web/api/notification/schema.py index 30ff2d5f2..30466bfa8 100644 --- a/backend/lcfs/web/api/notification/schema.py +++ b/backend/lcfs/web/api/notification/schema.py @@ -21,13 +21,6 @@ class NotificationUserProfileSchema(BaseSchema): organization_id: Optional[int] = None is_government: bool = False - @model_validator(mode="before") - def update_government_profile(cls, data): - if data.is_government: - data.first_name = "Government of B.C." - data.last_name = "" - return data - @computed_field @property def full_name(self) -> str: From 96c428a571737c5609123b840c7a05a24721eeb2 Mon Sep 17 00:00:00 2001 From: Kevin Hashimoto Date: Tue, 17 Dec 2024 16:41:38 -0800 Subject: [PATCH 3/5] fix: filter showing on other uses summary --- frontend/src/views/OtherUses/OtherUsesSummary.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/views/OtherUses/OtherUsesSummary.jsx b/frontend/src/views/OtherUses/OtherUsesSummary.jsx index 7c8020739..797ff8476 100644 --- a/frontend/src/views/OtherUses/OtherUsesSummary.jsx +++ b/frontend/src/views/OtherUses/OtherUsesSummary.jsx @@ -109,6 +109,7 @@ export const OtherUsesSummary = ({ data }) => { gridKey={'other-uses'} getRowId={getRowId} columnDefs={columns} + defaultColDef={{ filter: false, floatingFilter: false }} query={useGetOtherUses} queryParams={{ complianceReportId }} dataKey={'otherUses'} From fd1198c0e5e3fe3a86e7d095edf6a4f6116eb7fc Mon Sep 17 00:00:00 2001 From: Arturo Reyes Lopez Date: Tue, 17 Dec 2024 12:56:24 -0700 Subject: [PATCH 4/5] Add data transformation to show transport modes. --- .../FuelCodes/AddFuelCode/AddEditFuelCode.jsx | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/frontend/src/views/FuelCodes/AddFuelCode/AddEditFuelCode.jsx b/frontend/src/views/FuelCodes/AddFuelCode/AddEditFuelCode.jsx index ece671487..ca05f1413 100644 --- a/frontend/src/views/FuelCodes/AddFuelCode/AddEditFuelCode.jsx +++ b/frontend/src/views/FuelCodes/AddFuelCode/AddEditFuelCode.jsx @@ -97,7 +97,32 @@ const AddEditFuelCodeBase = () => { ) setColumnDefs(updatedColumnDefs) } - }, [errors, optionsData, existingFuelCode, hasRoles]) + }, [errors, optionsData, existingFuelCode]) + + useEffect(() => { + if (existingFuelCode) { + const transformedData = { + ...existingFuelCode, + feedstockFuelTransportMode: existingFuelCode.feedstockFuelTransportModes.map( + (mode) => mode.feedstockFuelTransportMode.transportMode + ), + finishedFuelTransportMode: existingFuelCode.finishedFuelTransportModes.map( + (mode) => mode.finishedFuelTransportMode.transportMode + ) + } + setRowData([transformedData]) + } else { + setRowData([ + { + id: uuid(), + prefixId: 1, + fuelSuffix: optionsData?.fuelCodePrefixes?.find( + (item) => item.prefix === 'BCLCF' + ).nextFuelCode + } + ]) + } + }, [optionsData, existingFuelCode, isGridReady]) const onGridReady = (params) => { setGridReady(true) From bce35792789e56667bd88ea68cc5bdc816abf076 Mon Sep 17 00:00:00 2001 From: Arturo Reyes Lopez Date: Tue, 17 Dec 2024 16:52:07 -0700 Subject: [PATCH 5/5] Supplier cannot add its own Organization as Legal Name Transaction Partner --- .../AddEditAllocationAgreements.jsx | 18 ++++++++++++++++-- .../src/views/AllocationAgreements/_schema.jsx | 9 ++++++--- .../AddEditNotionalTransfers.jsx | 18 ++++++++++++++++-- .../src/views/NotionalTransfers/_schema.jsx | 9 ++++++--- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/frontend/src/views/AllocationAgreements/AddEditAllocationAgreements.jsx b/frontend/src/views/AllocationAgreements/AddEditAllocationAgreements.jsx index 6a79fd45e..779d430e5 100644 --- a/frontend/src/views/AllocationAgreements/AddEditAllocationAgreements.jsx +++ b/frontend/src/views/AllocationAgreements/AddEditAllocationAgreements.jsx @@ -15,6 +15,7 @@ import { useGetAllocationAgreements, useSaveAllocationAgreement } from '@/hooks/useAllocationAgreement' +import { useCurrentUser } from '@/hooks/useCurrentUser' import { v4 as uuid } from 'uuid' import * as ROUTES from '@/constants/routes/routes.js' import { DEFAULT_CI_FUEL } from '@/constants/common' @@ -31,6 +32,7 @@ export const AddEditAllocationAgreements = () => { const params = useParams() const { complianceReportId, compliancePeriod } = params const navigate = useNavigate() + const { data: currentUser } = useCurrentUser() const { data: optionsData, @@ -117,9 +119,9 @@ export const AddEditAllocationAgreements = () => { ) useEffect(() => { - const updatedColumnDefs = allocationAgreementColDefs(optionsData, errors) + const updatedColumnDefs = allocationAgreementColDefs(optionsData, errors, currentUser) setColumnDefs(updatedColumnDefs) - }, [errors, optionsData]) + }, [errors, optionsData, currentUser]) useEffect(() => { if ( @@ -173,6 +175,18 @@ export const AddEditAllocationAgreements = () => { async (params) => { if (params.oldValue === params.newValue) return + // User cannot select their own organization as the transaction partner + if (params.colDef.field === 'transactionPartner') { + if (params.newValue === currentUser.organization.name) { + alertRef.current?.triggerAlert({ + message: 'You cannot select your own organization as the transaction partner.', + severity: 'error' + }) + params.node.setDataValue('transactionPartner', '') + return + } + } + const isValid = validate( params, (value) => { diff --git a/frontend/src/views/AllocationAgreements/_schema.jsx b/frontend/src/views/AllocationAgreements/_schema.jsx index e9d6e29d6..26ef36700 100644 --- a/frontend/src/views/AllocationAgreements/_schema.jsx +++ b/frontend/src/views/AllocationAgreements/_schema.jsx @@ -21,7 +21,7 @@ import { export const PROVISION_APPROVED_FUEL_CODE = 'Fuel code - section 19 (b) (i)' -export const allocationAgreementColDefs = (optionsData, errors) => [ +export const allocationAgreementColDefs = (optionsData, errors, currentUser) => [ validation, actions({ enableDuplicate: false, @@ -89,8 +89,11 @@ export const allocationAgreementColDefs = (optionsData, errors) => [ let path = apiRoutes.organizationSearch path += 'org_name=' + queryKey[1] const response = await client.get(path) - params.node.data.apiDataCache = response.data - return response.data + const filteredData = response.data.filter( + (org) => org.name !== currentUser.organization.name + ) + params.node.data.apiDataCache = filteredData + return filteredData }, title: 'transactionPartner', api: params.api, diff --git a/frontend/src/views/NotionalTransfers/AddEditNotionalTransfers.jsx b/frontend/src/views/NotionalTransfers/AddEditNotionalTransfers.jsx index 5d8073495..812192fa9 100644 --- a/frontend/src/views/NotionalTransfers/AddEditNotionalTransfers.jsx +++ b/frontend/src/views/NotionalTransfers/AddEditNotionalTransfers.jsx @@ -12,6 +12,7 @@ import { useGetAllNotionalTransfers, useSaveNotionalTransfer } from '@/hooks/useNotionalTransfer' +import { useCurrentUser } from '@/hooks/useCurrentUser' import { v4 as uuid } from 'uuid' import { BCGridEditor } from '@/components/BCDataGrid/BCGridEditor' import { useApiService } from '@/services/useApiService' @@ -37,6 +38,7 @@ export const AddEditNotionalTransfers = () => { useGetAllNotionalTransfers(complianceReportId) const { mutateAsync: saveRow } = useSaveNotionalTransfer() const navigate = useNavigate() + const { data: currentUser } = useCurrentUser() useEffect(() => { if (location?.state?.message) { @@ -115,6 +117,18 @@ export const AddEditNotionalTransfers = () => { async (params) => { if (params.oldValue === params.newValue) return + // User cannot select their own organization as the transaction partner + if (params.colDef.field === 'legalName') { + if (params.newValue === currentUser.organization.name) { + alertRef.current?.triggerAlert({ + message: 'You cannot select your own organization as the transaction partner.', + severity: 'error' + }) + params.node.setDataValue('legalName', '') + return + } + } + const isValid = validate( params, (value) => { @@ -223,10 +237,10 @@ export const AddEditNotionalTransfers = () => { useEffect(() => { if (!optionsLoading) { - const updatedColumnDefs = notionalTransferColDefs(optionsData, errors) + const updatedColumnDefs = notionalTransferColDefs(optionsData, errors, currentUser) setColumnDefs(updatedColumnDefs) } - }, [errors, optionsData, optionsLoading]) + }, [errors, optionsData, optionsLoading, currentUser]) const handleNavigateBack = useCallback(() => { navigate( diff --git a/frontend/src/views/NotionalTransfers/_schema.jsx b/frontend/src/views/NotionalTransfers/_schema.jsx index 6064debe4..a7a92353f 100644 --- a/frontend/src/views/NotionalTransfers/_schema.jsx +++ b/frontend/src/views/NotionalTransfers/_schema.jsx @@ -12,7 +12,7 @@ import { formatNumberWithCommas as valueFormatter } from '@/utils/formatters' import { apiRoutes } from '@/constants/routes' import { StandardCellErrors } from '@/utils/grid/errorRenderers' -export const notionalTransferColDefs = (optionsData, errors) => [ +export const notionalTransferColDefs = (optionsData, errors, currentUser) => [ validation, actions({ enableDuplicate: false, @@ -45,8 +45,11 @@ export const notionalTransferColDefs = (optionsData, errors) => [ let path = apiRoutes.organizationSearch path += 'org_name=' + queryKey[1] const response = await client.get(path) - params.node.data.apiDataCache = response.data - return response.data + const filteredData = response.data.filter( + (org) => org.name !== currentUser.organization.name + ) + params.node.data.apiDataCache = filteredData + return filteredData }, title: 'legalName', api: params.api