Skip to content

Commit 5d0cf6c

Browse files
authored
Merge pull request #4050 from bcgov/chore/merge-back-release-260316
Chore: Merge back release 260316
2 parents f47d69c + 860b49a commit 5d0cf6c

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

backend/lcfs/web/api/final_supply_equipment/repo.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ async def get_total_kwh_usage_for_report_group(
10181018
Return total kWh usage for effective FSE records in a report group.
10191019
10201020
Effective records are derived by keeping the latest record per
1021-
(charging_equipment_id, charging_equipment_version).
1021+
equipment group_uuid (which spans all versions of the same equipment).
10221022
"""
10231023
conditions = [
10241024
ComplianceReportChargingEquipment.compliance_report_group_uuid
@@ -1029,16 +1029,11 @@ async def get_total_kwh_usage_for_report_group(
10291029

10301030
dedup_subquery = (
10311031
select(
1032-
ComplianceReportChargingEquipment.charging_equipment_id.label(
1033-
"charging_equipment_id"
1034-
),
1035-
ComplianceReportChargingEquipment.charging_equipment_version.label(
1036-
"charging_equipment_version"
1037-
),
1032+
ChargingEquipment.group_uuid.label("equipment_group_uuid"),
10381033
ComplianceReportChargingEquipment.kwh_usage.label("kwh_usage"),
10391034
func.row_number()
10401035
.over(
1041-
partition_by=ComplianceReportChargingEquipment.charging_equipment_id,
1036+
partition_by=ChargingEquipment.group_uuid,
10421037
order_by=(
10431038
desc(ComplianceReportChargingEquipment.charging_equipment_version),
10441039
desc(
@@ -1048,6 +1043,11 @@ async def get_total_kwh_usage_for_report_group(
10481043
)
10491044
.label("row_number"),
10501045
)
1046+
.join(
1047+
ChargingEquipment,
1048+
ChargingEquipment.charging_equipment_id
1049+
== ComplianceReportChargingEquipment.charging_equipment_id,
1050+
)
10511051
.where(and_(*conditions))
10521052
.subquery()
10531053
)

frontend/src/hooks/useChargingSite.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,10 @@ export const useBulkUpdateEquipmentStatus = (options = {}) => {
332332
queryClient.invalidateQueries({
333333
queryKey: ['charging-site-equipment-paginated']
334334
})
335-
// 3. Invalidate all charging sites by organization queries
335+
// 3. Invalidate all charging sites list queries (both IDIR and org)
336+
queryClient.invalidateQueries({
337+
queryKey: ['chargingSitesAll']
338+
})
336339
queryClient.invalidateQueries({
337340
queryKey: ['chargingSitesByOrg']
338341
})

frontend/src/hooks/useFSEProcessing.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export const useFSEProcessing = (siteId) => {
4848
onSuccess: () => {
4949
queryClient.invalidateQueries({ queryKey: ['fse-processing'] })
5050
queryClient.invalidateQueries({ queryKey: ['charging-equipment'] })
51+
// Invalidate charging site list queries so the site disappears if all FSE are now draft
52+
queryClient.invalidateQueries({ queryKey: ['chargingSitesAll'] })
53+
queryClient.invalidateQueries({ queryKey: ['chargingSitesByOrg'] })
54+
queryClient.invalidateQueries({ queryKey: ['chargingSite'] })
5155
}
5256
})
5357

frontend/src/views/ChargingSite/components/ChargingSiteFSEGrid.jsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const ChargingSiteFSEGrid = ({
7070
return selectedEquipment.every((eq) => eq.status.status === 'Draft' || eq.status.status === 'Updated')
7171
}, [selectedRows, equipmentList])
7272

73-
// Check if selected equipment can be returned to draft (only from Submitted or Validated status)
73+
// Check if selected equipment can be returned to draft (only from Submitted status)
7474
const canReturnToDraft = useMemo(() => {
7575
if (selectedRows.length === 0) return false
7676
const selectedEquipment = equipmentList.filter((eq) =>
@@ -198,6 +198,20 @@ export const ChargingSiteFSEGrid = ({
198198
equipmentIds: selectedRows,
199199
newStatus
200200
})
201+
202+
// If moving to Draft, check if all equipment on this site will now be Draft
203+
if (newStatus === 'Draft') {
204+
const allWillBeDraft = equipmentList.every(
205+
(eq) =>
206+
selectedRows.includes(eq.chargingEquipmentId) ||
207+
eq.status.status === 'Draft'
208+
)
209+
if (allWillBeDraft) {
210+
navigate(ROUTES.REPORTS.CHARGING_SITE.INDEX)
211+
return
212+
}
213+
}
214+
201215
refetch()
202216
handleClearFilters()
203217
alertRef.current?.triggerAlert({
@@ -214,7 +228,7 @@ export const ChargingSiteFSEGrid = ({
214228
setModalData(null)
215229
}
216230
},
217-
[selectedRows, siteId, bulkUpdateStatus, handleClearFilters]
231+
[selectedRows, siteId, bulkUpdateStatus, handleClearFilters, equipmentList, navigate]
218232
)
219233

220234
const gridOptions = useMemo(

frontend/src/views/FSEProcessing/FSEProcessing.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,21 @@ export const FSEProcessing = () => {
234234
const equipmentIds = selectedRows.map((row) => row.charging_equipment_id)
235235
try {
236236
const result = await returnToDraft(equipmentIds)
237+
238+
// Check if all equipment on this site will now be Draft
239+
let allWillBeDraft = true
240+
gridRef.current?.api?.forEachNode((node) => {
241+
const isDraftTarget = equipmentIds.includes(node.data.charging_equipment_id)
242+
if (!isDraftTarget && node.data.status !== 'Draft') {
243+
allWillBeDraft = false
244+
}
245+
})
246+
247+
if (allWillBeDraft) {
248+
navigate(ROUTES.REPORTS.CHARGING_SITE.INDEX)
249+
return
250+
}
251+
237252
alertRef.current?.triggerAlert({
238253
message: result.message,
239254
severity: 'success'

0 commit comments

Comments
 (0)