Skip to content

Commit

Permalink
Merge branch 'release-0.2.0' into fix/alex-workflow-tests-241217
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexZorkin authored Dec 18, 2024
2 parents 9b208f1 + cf6599e commit ac810e0
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 24 deletions.
6 changes: 3 additions & 3 deletions backend/lcfs/web/api/final_supply_equipment/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
"""
Expand Down
7 changes: 0 additions & 7 deletions backend/lcfs/web/api/notification/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -31,6 +32,7 @@ export const AddEditAllocationAgreements = () => {
const params = useParams()
const { complianceReportId, compliancePeriod } = params
const navigate = useNavigate()
const { data: currentUser } = useCurrentUser()

const {
data: optionsData,
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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) => {
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/views/AllocationAgreements/_schema.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
27 changes: 26 additions & 1 deletion frontend/src/views/FuelCodes/AddFuelCode/AddEditFuelCode.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 16 additions & 2 deletions frontend/src/views/NotionalTransfers/AddEditNotionalTransfers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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) {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/views/NotionalTransfers/_schema.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions frontend/src/views/OtherUses/OtherUsesSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down

0 comments on commit ac810e0

Please sign in to comment.