Skip to content

Commit

Permalink
working Other Uses and exports
Browse files Browse the repository at this point in the history
  • Loading branch information
areyeslo committed Dec 23, 2024
1 parent ec4fba4 commit 65cfb8f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
10 changes: 10 additions & 0 deletions backend/lcfs/db/models/fuel/FuelCategory.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ class FuelCategory(BaseModel, Auditable, DisplayOrder, EffectiveDates):
"TargetCarbonIntensity", back_populates="fuel_category"
)
fuel_instances = relationship("FuelInstance", back_populates="fuel_category")

def __str__(self):
"""
Returns a string representation of the model's values.
"""
attributes = []
for attr in self.__mapper__.c:
value = getattr(self, attr.key, None)
attributes.append(f"{attr.key}: {value}")
return f"{self.__class__.__name__}({', '.join(attributes)})"
2 changes: 2 additions & 0 deletions backend/lcfs/web/api/other_uses/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ async def schema_to_model(self, other_use: OtherUsesCreateSchema) -> OtherUses:
fuel_category = await self.fuel_repo.get_fuel_category_by(
category=other_use.fuel_category
)
print("fuel_category", fuel_category)
fuel_type = await self.fuel_repo.get_fuel_type_by_name(other_use.fuel_type)
expected_use = await self.fuel_repo.get_expected_use_type_by_name(
other_use.expected_use
Expand Down Expand Up @@ -206,6 +207,7 @@ async def update_other_use(
category=other_use_data.fuel_category
)
)
print("other_use.fuel_category", other_use.fuel_category)

if other_use.expected_use.name != other_use_data.expected_use:
other_use.expected_use = (
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/assets/locales/en/fuelExport.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"fuelExportColLabels": {
"complianceReportId": "Compliance Report ID",
"fuelExportId": "Fuel export ID",
"fuelType": "Fuel type",
"fuelTypeId": "Fuel type",
"exportDate": "Export date",
"fuelTypeOther": "Fuel type other",
"fuelCategory": "Fuel catgory",
"fuelCategoryId": "Fuel category",
"endUse": "End use",
"provisionOfTheActId": "Determining carbon intensity",
"fuelCode": "Fuel code",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export const AddEditAllocationAgreements = () => {
severity: 'pending'
})

console.log('params.node.data', params.node.data)
let updatedData = Object.entries(params.node.data)
.filter(([, value]) => value !== null && value !== '')
.reduce((acc, [key, value]) => {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/views/FuelExports/AddEditFuelExports.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export const AddEditFuelExports = () => {
severity: 'pending'
})

console.log('params.node.data', params.node.data)
// clean up any null or empty string values
let updatedData = Object.entries(params.node.data)
.filter(([, value]) => value !== null && value !== '')
Expand Down
21 changes: 16 additions & 5 deletions frontend/src/views/FuelExports/_schema.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ export const fuelExportColDefs = (optionsData, errors, gridReady) => [
}
},
{
field: 'fuelType',
field: 'fuelTypeId',
headerComponent: RequiredHeader,
headerName: i18n.t('fuelExport:fuelExportColLabels.fuelType'),
headerName: i18n.t('fuelExport:fuelExportColLabels.fuelTypeId'),
cellEditor: AutocompleteCellEditor,
cellRenderer: (params) =>
params.value ||
Expand All @@ -135,10 +135,21 @@ export const fuelExportColDefs = (optionsData, errors, gridReady) => [
const fuelType = optionsData?.fuelTypes?.find(
(obj) => obj.fuelType === params.newValue
)
console.log("fuelType", fuelType)
console.log("fuelType.fuelCategories.length: ", fuelType.fuelCategories.length)
console.log("fuelType.fuelCategories[0].fuelCategory: ", fuelType.fuelCategories[0].fuelCategory )
params.data.fuelType = params.newValue
params.data.fuelTypeId = fuelType?.fuelTypeId
params.data.fuelTypeOther = undefined
params.data.fuelCategory = undefined
// Set both category and categoryId if single option exists
if (fuelType?.fuelCategories?.length === 1) {
const category = fuelType.fuelCategories[0]
params.data.fuelCategory = category.fuelCategory
params.data.fuelCategoryId = category.fuelCategoryId
} else {
params.data.fuelCategory = undefined
params.data.fuelCategoryId = undefined
}
params.data.endUseId = undefined
params.data.endUseType = undefined
params.data.eer = undefined
Expand Down Expand Up @@ -180,9 +191,9 @@ export const fuelExportColDefs = (optionsData, errors, gridReady) => [
minWidth: 250
},
{
field: 'fuelCategory',
field: 'fuelCategoryId',
headerComponent: RequiredHeader,
headerName: i18n.t('fuelExport:fuelExportColLabels.fuelCategory'),
headerName: i18n.t('fuelExport:fuelExportColLabels.fuelCategoryId'),
cellEditor: AutocompleteCellEditor,
cellRenderer: (params) =>
params.value ||
Expand Down

0 comments on commit 65cfb8f

Please sign in to comment.