Skip to content

Commit

Permalink
Merge pull request #1561 from bcgov/LCFS-1509-OtherUse-Exports
Browse files Browse the repository at this point in the history
LCFS-1509:  Fuels for other use and Export fuels not saving
  • Loading branch information
areyeslo authored Dec 30, 2024
2 parents 04035e3 + 147a234 commit 64b5b3d
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(),
)

Expand Down Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions backend/lcfs/tests/fuel_export/test_fuel_exports_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
10 changes: 10 additions & 0 deletions backend/lcfs/tests/fuel_export/test_fuel_exports_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions backend/lcfs/web/api/fuel_export/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/assets/locales/en/fuelExport.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/views/FuelExports/AddEditFuelExports.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 7 additions & 7 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 @@ -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
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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
},
Expand All @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/views/OtherUses/AddEditOtherUses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 64b5b3d

Please sign in to comment.