diff --git a/backend/lcfs/tests/fuel_export/test_fuel_exports_actions_service.py b/backend/lcfs/tests/fuel_export/test_fuel_exports_actions_service.py index 048259c8b..007f9f365 100644 --- a/backend/lcfs/tests/fuel_export/test_fuel_exports_actions_service.py +++ b/backend/lcfs/tests/fuel_export/test_fuel_exports_actions_service.py @@ -148,6 +148,10 @@ async def test_create_fuel_export_success( } created_export.fuel_category = {"category": "Diesel"} created_export.units = "Litres" + created_export.provision_of_the_act = { + "provision_of_the_act_id": 3, + "name": "Test Provision" + } mock_repo.create_fuel_export.return_value = created_export # Call the method under test @@ -190,6 +194,10 @@ async def test_update_fuel_export_success_existing_report( } existing_export.fuel_category = {"category": "Diesel"} existing_export.units = "Litres" + existing_export.provision_of_the_act = { + "provision_of_the_act_id": 123, + "name": "Test Provision" + } mock_repo.get_fuel_export_version_by_user.return_value = existing_export # Mock the response from get_standardized_fuel_data @@ -214,6 +222,11 @@ async def test_update_fuel_export_success_existing_report( } updated_export.fuel_category = {"category": "Diesel"} updated_export.units = "Litres" + + updated_export.provision_of_the_act = { + "provision_of_the_act_id": 123, + "name": "Test Provision" + } mock_repo.update_fuel_export.return_value = updated_export # Call the method under test @@ -256,6 +269,10 @@ async def test_update_fuel_export_create_new_version( } existing_export.fuel_category = {"category": "Diesel"} existing_export.units = "Litres" + existing_export.provision_of_the_act = { + "provision_of_the_act_id": 123, + "name": "Test Provision" + } mock_repo.get_fuel_export_version_by_user.return_value = existing_export # Mock the response from get_standardized_fuel_data @@ -281,6 +298,10 @@ async def test_update_fuel_export_create_new_version( } new_export.fuel_category = {"category": "Diesel"} new_export.units = "Litres" + new_export.provision_of_the_act = { + "provision_of_the_act_id": 123, + "name": "Test Provision" + } mock_repo.create_fuel_export.return_value = new_export # Call the method under test @@ -458,6 +479,7 @@ async def test_compliance_units_calculation( group_uuid=str(uuid4()), version=0, provisionOfTheActId=123, + provisionOfTheAct={"provision_of_the_act_id": 123, "name": "Test Provision"}, exportDate=datetime.now().date(), ) @@ -488,6 +510,11 @@ async def create_fuel_export_side_effect(fuel_export: FuelExport): fuel_export.fuel_category = {"category": "Diesel"} fuel_export.units = "Litres" + fuel_export.provision_of_the_act = { + "provision_of_the_act_id": fuel_export.provision_of_the_act_id, + "name": "Test Provision" + } + # The service should have already calculated compliance_units return fuel_export diff --git a/backend/lcfs/tests/fuel_export/test_fuel_exports_services.py b/backend/lcfs/tests/fuel_export/test_fuel_exports_services.py index 92d35bd4d..2d071fc85 100644 --- a/backend/lcfs/tests/fuel_export/test_fuel_exports_services.py +++ b/backend/lcfs/tests/fuel_export/test_fuel_exports_services.py @@ -57,6 +57,10 @@ async def test_get_fuel_export_list_success(fuel_export_service, mock_repo): export_date=date.today(), group_uuid="test-uuid", provision_of_the_act_id=1, + provision_of_the_act={ + "provision_of_the_act_id": 1, + "name": "Test Provision" + }, version=0, user_type=UserTypeEnum.SUPPLIER, action_type=ActionTypeEnum.CREATE, @@ -81,6 +85,11 @@ async def test_get_fuel_exports_paginated_success(fuel_export_service, mock_repo quantity=100, units="L", export_date=date.today(), + provision_of_the_act_id=1, + provision_of_the_act={ + "provision_of_the_act_id": 1, + "name": "Test Provision" + }, ) mock_repo.get_fuel_exports_paginated.return_value = ([mock_export], 1) @@ -122,6 +131,10 @@ async def test_action_create_fuel_export_success(fuel_export_action_service, moc user_type=UserTypeEnum.SUPPLIER, action_type=ActionTypeEnum.CREATE, provision_of_the_act_id=1, + provision_of_the_act={ + "provision_of_the_act_id": 1, + "name": "Act Provision" + }, fuel_type_id=1, fuel_category_id=1, quantity=100, @@ -168,6 +181,10 @@ async def test_action_update_fuel_export_success(fuel_export_action_service, moc fuel_type_id=1, fuel_category_id=1, provision_of_the_act_id=1, + provision_of_the_act={ + "provision_of_the_act_id": 1, + "name": "Act Provision" + }, quantity=100, units="L", export_date=date.today(), diff --git a/backend/lcfs/tests/fuel_export/test_fuel_exports_views.py b/backend/lcfs/tests/fuel_export/test_fuel_exports_views.py index 9afa2e68d..e749a051e 100644 --- a/backend/lcfs/tests/fuel_export/test_fuel_exports_views.py +++ b/backend/lcfs/tests/fuel_export/test_fuel_exports_views.py @@ -233,6 +233,11 @@ async def test_save_fuel_export_row_update_success(client, fastapi_app, set_mock export_date="2024-01-01", fuel_category_id=1, fuel_category=FuelCategoryResponseSchema(category="Diesel"), + provisionOfTheActId=1, + provisionOfTheAct={ + "provision_of_the_act_id": 1, + "name": "Test Provision" + } ) # Create update payload with all required fields @@ -301,6 +306,11 @@ async def test_save_fuel_export_row_create_success(client, fastapi_app, set_mock export_date="2024-01-01", fuel_category_id=1, fuel_category=FuelCategoryResponseSchema(category="Diesel"), + provisionOfTheActId=1, + provisionOfTheAct={ + "provision_of_the_act_id": 1, + "name": "Section 6" + } ) mock_validate_organization_access.return_value = None diff --git a/backend/lcfs/web/api/fuel_export/schema.py b/backend/lcfs/web/api/fuel_export/schema.py index f3a5d7584..2a60f8fa4 100644 --- a/backend/lcfs/web/api/fuel_export/schema.py +++ b/backend/lcfs/web/api/fuel_export/schema.py @@ -122,8 +122,8 @@ class FuelExportSchema(BaseSchema): fuel_category: FuelCategoryResponseSchema end_use_id: Optional[int] = None end_use_type: Optional[EndUseTypeSchema] = None - provision_of_the_act_id: Optional[int] = None - provision_of_the_act: Optional[ProvisionOfTheActSchema] = None + provision_of_the_act_id: int + provision_of_the_act: ProvisionOfTheActSchema fuel_type_other: Optional[str] = None quantity: int = Field(..., gt=0) units: str diff --git a/frontend/src/assets/locales/en/fuelExport.json b/frontend/src/assets/locales/en/fuelExport.json index 3050cb2da..cc2cac887 100644 --- a/frontend/src/assets/locales/en/fuelExport.json +++ b/frontend/src/assets/locales/en/fuelExport.json @@ -12,11 +12,11 @@ "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", - "endUse": "End use", + "fuelCategoryId": "Fuel category", + "endUseId": "End use", "provisionOfTheActId": "Determining carbon intensity", "fuelCode": "Fuel code", "quantity": "Quantity supplied", diff --git a/frontend/src/views/FuelExports/AddEditFuelExports.jsx b/frontend/src/views/FuelExports/AddEditFuelExports.jsx index 577cde049..b76c87de6 100644 --- a/frontend/src/views/FuelExports/AddEditFuelExports.jsx +++ b/frontend/src/views/FuelExports/AddEditFuelExports.jsx @@ -128,13 +128,16 @@ export const AddEditFuelExports = () => { const onCellValueChanged = useCallback( async (params) => { - if (params.column.colId === 'fuelType') { + if (params.column.colId === 'fuelTypeId') { const options = optionsData?.fuelTypes ?.find((obj) => params.node.data.fuelType === obj.fuelType) ?.fuelCategories.map((item) => item.fuelCategory) - if (options.length === 1) { - params.node.setDataValue('fuelCategory', options[0]) - } + + const categoryValue = options.length === 1 + ? options[0] + : null + + params.node.setDataValue('fuelCategoryId', categoryValue) } }, [optionsData] diff --git a/frontend/src/views/FuelExports/_schema.jsx b/frontend/src/views/FuelExports/_schema.jsx index 41021fe27..7286a7f3b 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 || @@ -139,12 +139,13 @@ export const fuelExportColDefs = (optionsData, errors, gridReady) => [ params.data.fuelTypeId = fuelType?.fuelTypeId params.data.fuelTypeOther = undefined params.data.fuelCategory = undefined + params.data.fuelCategoryId = undefined params.data.endUseId = undefined params.data.endUseType = undefined params.data.eer = undefined params.data.provisionOfTheAct = undefined + params.data.provisionOfTheActId = undefined params.data.fuelCode = undefined - params.data.quantity = 0 params.data.units = fuelType?.unit } return true @@ -180,9 +181,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 || @@ -211,7 +212,6 @@ export const fuelExportColDefs = (optionsData, errors, gridReady) => [ params.data.eer = undefined params.data.provisionOfTheAct = undefined params.data.fuelCode = undefined - params.data.quantity = 0 } return true }, @@ -236,7 +236,7 @@ export const fuelExportColDefs = (optionsData, errors, gridReady) => [ { field: 'endUseType', headerComponent: RequiredHeader, - headerName: i18n.t('fuelExport:fuelExportColLabels.endUse'), + headerName: i18n.t('fuelExport:fuelExportColLabels.endUseId'), options: (params) => [ ...new Set( diff --git a/frontend/src/views/OtherUses/AddEditOtherUses.jsx b/frontend/src/views/OtherUses/AddEditOtherUses.jsx index d3fc18ec8..944a6ac67 100644 --- a/frontend/src/views/OtherUses/AddEditOtherUses.jsx +++ b/frontend/src/views/OtherUses/AddEditOtherUses.jsx @@ -197,7 +197,12 @@ export const AddEditOtherUses = () => { const fuelCategoryOptions = fuelType.fuelCategories.map( (item) => item.category ); - params.node.setDataValue('fuelCategory', fuelCategoryOptions[0] ?? null); + + const categoryValue = fuelCategoryOptions.length === 1 + ? fuelCategoryOptions[0] + : null + + params.node.setDataValue('fuelCategory', categoryValue); // Auto-populate the "fuelCode" field const fuelCodeOptions = fuelType.fuelCodes.map(