Skip to content

Commit 598ebd7

Browse files
authored
Merge pull request #2542 from bcgov/feat/prashanth-edit-addr-analyst-2515
Feat: LCFS - Edit Address in CR for analyst #2515
2 parents 536f234 + 53970cd commit 598ebd7

File tree

8 files changed

+64
-30
lines changed

8 files changed

+64
-30
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,7 @@ async def get_fuel_type_options(
299299
query = query.where(FuelCategory.fuel_category_id == fuel_category_id)
300300
if fuel_type_id:
301301
query = query.where(FuelType.fuel_type_id == fuel_type_id)
302-
print("Generated SQL Query:")
303-
from sqlalchemy.dialects import postgresql
304302

305-
print(
306-
query.compile(
307-
dialect=postgresql.dialect(), compile_kwargs={"literal_binds": True}
308-
)
309-
)
310303
fuel_type_results = (await self.db.execute(query)).all()
311304

312305
return {

backend/lcfs/web/api/compliance_report/summary_repo.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ async def get_previous_summary(
144144
)
145145
.limit(1)
146146
)
147-
return result.scalars().first().summary
147+
previous_report = result.scalars().first()
148+
if previous_report is not None:
149+
return previous_report.summary
150+
return None
148151

149152
@repo_handler
150153
async def get_transferred_out_compliance_units(
@@ -213,13 +216,17 @@ def aggregate_quantities(
213216
and record.fuel_type.fossil_derived == fossil_derived
214217
):
215218
fuel_category = self._format_category(record.fuel_category.category)
216-
fuel_quantities[fuel_category] += record.quantity
219+
fuel_quantities[fuel_category] = fuel_quantities.get(
220+
fuel_category, 0
221+
) + (record.quantity or 0)
217222
elif (
218223
isinstance(record, OtherUses)
219224
and record.fuel_type.fossil_derived == fossil_derived
220225
):
221226
fuel_category = self._format_category(record.fuel_category.category)
222-
fuel_quantities[fuel_category] += record.quantity_supplied
227+
fuel_quantities[fuel_category] = fuel_quantities.get(
228+
fuel_category, 0
229+
) + (record.quantity_supplied or 0)
223230

224231
return dict(fuel_quantities)
225232

frontend/src/assets/locales/en/reports.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
},
1313
"noReportsFound": "No compliance reports found",
1414
"serviceAddrLabel": "Address for service",
15+
"hoAddrLabel": "Head office (optional)",
16+
"hoAddrLabelView": "Head office address",
17+
"hoAddrLabelEdit": "Head office address (can be an international address)",
1518
"orgDetailsForm": {
1619
"serviceAddrLabelView": "Address for service in B.C.",
1720
"serviceAddrLabelEdit": "Address for service in B.C. (postal address)",
18-
"bcRecordLabelView": "Address in B.C. (where records are maintained)",
19-
"bcRecordLabelEdit": "Address in B.C. (where records are maintained, optional)"
21+
"bcRecordLabel": "Address in B.C. where records are maintained"
2022
},
21-
"hoAddrLabel": "Head office (optional)",
22-
"hoAddrLabelView": "Head office address",
23-
"hoAddrLabelEdit": "Head office address (can be an international address, optional)",
2423
"bcRecordLabel": "Address in B.C. (where records are maintained)",
2524
"activityHdrLabel": "Did <b>{{name}}</b> engage in any of the following activities between January 1, {{period}}, and December 31, {{period}}?",
2625
"quarterlyActivityHdrLabel": "Report your quarter {{quarter}} fuel supply as well as any supporting documents.",

frontend/src/components/BCDataGrid/BCGridViewer.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ export const BCGridViewer = forwardRef(
113113
})
114114
]
115115

116-
onPaginationChange({ ...paginationOptions, page: 1, filters: filterArr })
116+
onPaginationChange({
117+
...paginationOptions,
118+
page: 1,
119+
filters: filterArr
120+
})
117121
sessionStorage.setItem(`${gridKey}-filter`, JSON.stringify(gridFilters))
118122
},
119123
[gridKey, onPaginationChange, paginationOptions.filters]
@@ -184,7 +188,7 @@ export const BCGridViewer = forwardRef(
184188
defaultColDef={{ ...defaultColDefParams, ...defaultColDef }}
185189
columnDefs={columnDefs}
186190
gridOptions={gridOptions}
187-
rowData={!isLoading && data[dataKey]}
191+
rowData={!isLoading && (data[dataKey] || [])}
188192
onGridReady={onGridReady}
189193
onSortChanged={handleSortChanged}
190194
onFilterChanged={handleFilterChanged}

frontend/src/views/ComplianceReports/components/AssessmentCard.jsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { roles } from '@/constants/roles'
88
import { apiRoutes } from '@/constants/routes/index.js'
99
import { COMPLIANCE_REPORT_STATUSES } from '@/constants/statuses'
1010
import { useCreateSupplementalReport } from '@/hooks/useComplianceReports'
11+
import { useCurrentUser } from '@/hooks/useCurrentUser'
1112
import { useOrganizationSnapshot } from '@/hooks/useOrganizationSnapshot.js'
1213
import { useApiService } from '@/services/useApiService.js'
1314
import { HistoryCard } from '@/views/ComplianceReports/components/HistoryCard.jsx'
@@ -32,6 +33,7 @@ export const AssessmentCard = ({
3233
const { t } = useTranslation(['report', 'org'])
3334
const navigate = useNavigate()
3435
const apiService = useApiService()
36+
const { hasRoles } = useCurrentUser()
3537

3638
const [isEditing, setIsEditing] = useState(false)
3739

@@ -85,6 +87,15 @@ export const AssessmentCard = ({
8587
return chain.filter((report) => report.history && report.history.length > 0)
8688
}, [chain])
8789

90+
const isAddressEditable = useMemo(() => {
91+
return (
92+
!isEditing &&
93+
(currentStatus === COMPLIANCE_REPORT_STATUSES.DRAFT ||
94+
(hasRoles(roles.analyst) &&
95+
currentStatus === COMPLIANCE_REPORT_STATUSES.SUBMITTED))
96+
)
97+
}, [isEditing, currentStatus, hasRoles])
98+
8899
return (
89100
<BCWidgetCard
90101
component="div"
@@ -97,12 +108,11 @@ export const AssessmentCard = ({
97108
: t('report:orgDetails')
98109
}
99110
editButton={
100-
(!isEditing &&
101-
currentStatus === COMPLIANCE_REPORT_STATUSES.DRAFT && {
102-
onClick: onEdit,
103-
text: 'Edit',
104-
id: 'edit'
105-
}) ||
111+
(isAddressEditable && {
112+
onClick: onEdit,
113+
text: 'Edit',
114+
id: 'edit'
115+
}) ||
106116
null
107117
}
108118
content={
@@ -167,7 +177,7 @@ export const AssessmentCard = ({
167177
onClick={() => {
168178
createSupplementalReport()
169179
}}
170-
startIcon={<Assignment />}
180+
startIcon={<Assignment fontSize="1rem !important" />}
171181
sx={{ mt: 3 }}
172182
disabled={isLoading}
173183
>

frontend/src/views/ComplianceReports/components/OrganizationAddress.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,7 @@ export const OrganizationAddress = ({
238238
},
239239
{
240240
name: 'recordsAddress',
241-
label: isEditing
242-
? t('report:orgDetailsForm.bcRecordLabelEdit')
243-
: t('report:orgDetailsForm.bcRecordLabelView'),
241+
label: t('report:orgDetailsForm.bcRecordLabel'),
244242
checkbox: true,
245243
checkboxLabel: 'same as address for service',
246244
onCheckboxChange: handleSameAddressChange,

frontend/src/views/ComplianceReports/components/ReportDetails.jsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ import {
5050
DeleteOutline,
5151
Edit,
5252
ExpandMore,
53-
InfoOutlined
53+
InfoOutlined,
54+
NewReleasesOutlined
5455
} from '@mui/icons-material'
5556

5657
const chipStyles = {
@@ -379,6 +380,15 @@ const ReportDetails = ({ canEdit, currentStatus = 'Draft', userRoles }) => {
379380
return (
380381
((scheduleData && !isArrayEmpty(scheduleData)) || hasVersions) && (
381382
<Accordion
383+
sx={{
384+
'& .Mui-disabled': {
385+
backgroundColor: colors.light.main,
386+
opacity: '0.8 !important',
387+
'& .MuiTypography-root': {
388+
color: 'initial !important',
389+
}
390+
}
391+
}}
382392
key={index}
383393
expanded={
384394
expanded.includes(`panel${index}`) &&
@@ -423,7 +433,20 @@ const ReportDetails = ({ canEdit, currentStatus = 'Draft', userRoles }) => {
423433
</Role>
424434
)}{' '}
425435
{wasEdited(data?.[activity.key]) && (
426-
<StyledChip color="primary" label="Edited" />
436+
<Chip
437+
aria-label="changes were made since original report"
438+
icon={<NewReleasesOutlined fontSize="small" />}
439+
label={t('Edited')}
440+
size="small"
441+
sx={{
442+
...chipStyles,
443+
color: colors.alerts.success.color,
444+
'& .MuiChip-icon': {
445+
color: colors.alerts.success.color
446+
},
447+
backgroundImage: `linear-gradient(195deg, ${colors.alerts.success.border},${colors.alerts.success.background})`
448+
}}
449+
/>
427450
)}
428451
</BCTypography>
429452
{allRecordsDeleted && (

frontend/src/views/ComplianceReports/components/__tests__/OrganizationAddress.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ describe('OrganizationAddress', () => {
216216

217217
// The same check applies to the records address label:
218218
expect(
219-
screen.getByText('report:orgDetailsForm.bcRecordLabelView:')
219+
screen.getByText('report:orgDetailsForm.bcRecordLabel:')
220220
).toBeInTheDocument()
221221
// No "Required" label for empty optional address
222222
expect(screen.queryByText('Required')).not.toBeInTheDocument()

0 commit comments

Comments
 (0)