From 65cfb8f42a2e0b0f8c357370adfcb5383b4b3662 Mon Sep 17 00:00:00 2001 From: Arturo Reyes Lopez Date: Mon, 23 Dec 2024 08:36:39 -0700 Subject: [PATCH] working Other Uses and exports --- backend/lcfs/db/models/fuel/FuelCategory.py | 10 +++++++++ backend/lcfs/web/api/other_uses/services.py | 2 ++ .../src/assets/locales/en/fuelExport.json | 4 ++-- .../AddEditAllocationAgreements.jsx | 1 + .../views/FuelExports/AddEditFuelExports.jsx | 1 + frontend/src/views/FuelExports/_schema.jsx | 21 ++++++++++++++----- 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/backend/lcfs/db/models/fuel/FuelCategory.py b/backend/lcfs/db/models/fuel/FuelCategory.py index f4d3f0791..0fdde9177 100644 --- a/backend/lcfs/db/models/fuel/FuelCategory.py +++ b/backend/lcfs/db/models/fuel/FuelCategory.py @@ -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)})" diff --git a/backend/lcfs/web/api/other_uses/services.py b/backend/lcfs/web/api/other_uses/services.py index db5b22f81..72ea07ad7 100644 --- a/backend/lcfs/web/api/other_uses/services.py +++ b/backend/lcfs/web/api/other_uses/services.py @@ -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 @@ -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 = ( diff --git a/frontend/src/assets/locales/en/fuelExport.json b/frontend/src/assets/locales/en/fuelExport.json index 3050cb2da..ca39a15ac 100644 --- a/frontend/src/assets/locales/en/fuelExport.json +++ b/frontend/src/assets/locales/en/fuelExport.json @@ -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", diff --git a/frontend/src/views/AllocationAgreements/AddEditAllocationAgreements.jsx b/frontend/src/views/AllocationAgreements/AddEditAllocationAgreements.jsx index 779d430e5..a6e6de5bc 100644 --- a/frontend/src/views/AllocationAgreements/AddEditAllocationAgreements.jsx +++ b/frontend/src/views/AllocationAgreements/AddEditAllocationAgreements.jsx @@ -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]) => { diff --git a/frontend/src/views/FuelExports/AddEditFuelExports.jsx b/frontend/src/views/FuelExports/AddEditFuelExports.jsx index 577cde049..d56e4bf87 100644 --- a/frontend/src/views/FuelExports/AddEditFuelExports.jsx +++ b/frontend/src/views/FuelExports/AddEditFuelExports.jsx @@ -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 !== '') diff --git a/frontend/src/views/FuelExports/_schema.jsx b/frontend/src/views/FuelExports/_schema.jsx index 60656d905..079b76517 100644 --- a/frontend/src/views/FuelExports/_schema.jsx +++ b/frontend/src/views/FuelExports/_schema.jsx @@ -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 || @@ -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 @@ -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 ||