From 24a86d70ee61a3b6f72a8ceba4a4def80266a065 Mon Sep 17 00:00:00 2001 From: Arturo Reyes Lopez Date: Thu, 9 Jan 2025 18:26:46 -0700 Subject: [PATCH 1/3] Update other_uses_fossil_derived in fuel_type table. --- .../versions/2025-01-09-18-12_fe03799b4018.py | 61 +++++++++++++++++++ backend/lcfs/web/api/other_uses/repo.py | 1 + .../src/views/OtherUses/AddEditOtherUses.jsx | 9 +++ 3 files changed, 71 insertions(+) create mode 100644 backend/lcfs/db/migrations/versions/2025-01-09-18-12_fe03799b4018.py diff --git a/backend/lcfs/db/migrations/versions/2025-01-09-18-12_fe03799b4018.py b/backend/lcfs/db/migrations/versions/2025-01-09-18-12_fe03799b4018.py new file mode 100644 index 000000000..d171baff9 --- /dev/null +++ b/backend/lcfs/db/migrations/versions/2025-01-09-18-12_fe03799b4018.py @@ -0,0 +1,61 @@ +"""Update other_uses_fossil_derived in fuel_type + +Revision ID: fe03799b4018 +Revises: fa98709e7952 +Create Date: 2025-01-09 18:12:43.683691 + +""" + +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "fe03799b4018" +down_revision = "fa98709e7952" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # Set other_uses_fossil_derived to false + op.execute(""" + UPDATE fuel_type + SET other_uses_fossil_derived = false + WHERE fuel_type IN ( + 'CNG', 'Electricity', 'Hydrogen', 'LNG', 'Propane', + 'Natural gas-based gasoline', 'Petroleum-based diesel', + 'Petroleum-based gasoline' + ) + """) + + # Set other_uses_fossil_derived to true + op.execute(""" + UPDATE fuel_type + SET other_uses_fossil_derived = true + WHERE fuel_type IN ( + 'Alternative jet fuel', 'Biodiesel', 'Ethanol', 'HDRD', + 'Other diesel fuel', 'Renewable gasoline', 'Renewable naphtha' + ) + """) + +def downgrade() -> None: + # Revert `other_uses_fossil_derived` to original values for false + op.execute(""" + UPDATE fuel_type + SET other_uses_fossil_derived = true + WHERE fuel_type IN ( + 'CNG', 'Electricity', 'Hydrogen', 'LNG', 'Propane', + 'Natural gas-based gasoline', 'Petroleum-based diesel', + 'Petroleum-based gasoline' + ) + """) + + # Revert `other_uses_fossil_derived` to original values for true + op.execute(""" + UPDATE fuel_type + SET other_uses_fossil_derived = false + WHERE fuel_type IN ( + 'Alternative jet fuel', 'Biodiesel', 'Ethanol', 'HDRD', + 'Other diesel fuel', 'Renewable gasoline', 'Renewable naphtha' + ) + """) diff --git a/backend/lcfs/web/api/other_uses/repo.py b/backend/lcfs/web/api/other_uses/repo.py index 274354acd..c9f9dd13a 100644 --- a/backend/lcfs/web/api/other_uses/repo.py +++ b/backend/lcfs/web/api/other_uses/repo.py @@ -350,6 +350,7 @@ async def get_formatted_fuel_types( joinedload(FuelType.provision_1), joinedload(FuelType.provision_2), ) + .order_by(FuelType.fuel_type) ) result = await self.db.execute(query) diff --git a/frontend/src/views/OtherUses/AddEditOtherUses.jsx b/frontend/src/views/OtherUses/AddEditOtherUses.jsx index 5f101aeea..c65c10b9c 100644 --- a/frontend/src/views/OtherUses/AddEditOtherUses.jsx +++ b/frontend/src/views/OtherUses/AddEditOtherUses.jsx @@ -208,6 +208,15 @@ export const AddEditOtherUses = () => { params.node.setDataValue('fuelCategory', categoryValue) + // Auto populate the "provisionOfTheAct" field + const provisions = fuelType.provisionOfTheAct.map( + (provision) => provision.name + ) + + const provisionValue = + provisions.length === 1 ? provisions[0] : null + params.node.setDataValue('provisionOfTheAct', provisionValue) + // Auto-populate the "fuelCode" field const fuelCodeOptions = fuelType.fuelCodes.map( (code) => code.fuelCode From 54daf57ad72a2f94b7b7ec8a06ef9f7501263b04 Mon Sep 17 00:00:00 2001 From: Arturo Reyes Lopez Date: Tue, 14 Jan 2025 16:07:21 -0700 Subject: [PATCH 2/3] Update down_revision in migration. --- ...18-12_fe03799b4018.py => 2025-01-11-18-12_fe03799b4018.py} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename backend/lcfs/db/migrations/versions/{2025-01-09-18-12_fe03799b4018.py => 2025-01-11-18-12_fe03799b4018.py} (96%) diff --git a/backend/lcfs/db/migrations/versions/2025-01-09-18-12_fe03799b4018.py b/backend/lcfs/db/migrations/versions/2025-01-11-18-12_fe03799b4018.py similarity index 96% rename from backend/lcfs/db/migrations/versions/2025-01-09-18-12_fe03799b4018.py rename to backend/lcfs/db/migrations/versions/2025-01-11-18-12_fe03799b4018.py index d171baff9..dc4d5b93e 100644 --- a/backend/lcfs/db/migrations/versions/2025-01-09-18-12_fe03799b4018.py +++ b/backend/lcfs/db/migrations/versions/2025-01-11-18-12_fe03799b4018.py @@ -2,7 +2,7 @@ Revision ID: fe03799b4018 Revises: fa98709e7952 -Create Date: 2025-01-09 18:12:43.683691 +Create Date: 2025-01-11 18:12:43.683691 """ @@ -11,7 +11,7 @@ # revision identifiers, used by Alembic. revision = "fe03799b4018" -down_revision = "fa98709e7952" +down_revision = "d25e7c47659e" branch_labels = None depends_on = None From ef67759e54fb6fd6ff04d2536d447022d4ac4323 Mon Sep 17 00:00:00 2001 From: Arturo Reyes Lopez Date: Thu, 16 Jan 2025 13:16:46 -0700 Subject: [PATCH 3/3] Updating migration. Updating label in fuels for other use --- ...18-12_fe03799b4018.py => 2025-01-14-18-12_fe03799b4018.py} | 4 ++-- frontend/src/views/OtherUses/OtherUsesSummary.jsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename backend/lcfs/db/migrations/versions/{2025-01-11-18-12_fe03799b4018.py => 2025-01-14-18-12_fe03799b4018.py} (96%) diff --git a/backend/lcfs/db/migrations/versions/2025-01-11-18-12_fe03799b4018.py b/backend/lcfs/db/migrations/versions/2025-01-14-18-12_fe03799b4018.py similarity index 96% rename from backend/lcfs/db/migrations/versions/2025-01-11-18-12_fe03799b4018.py rename to backend/lcfs/db/migrations/versions/2025-01-14-18-12_fe03799b4018.py index dc4d5b93e..8afe58102 100644 --- a/backend/lcfs/db/migrations/versions/2025-01-11-18-12_fe03799b4018.py +++ b/backend/lcfs/db/migrations/versions/2025-01-14-18-12_fe03799b4018.py @@ -2,7 +2,7 @@ Revision ID: fe03799b4018 Revises: fa98709e7952 -Create Date: 2025-01-11 18:12:43.683691 +Create Date: 2025-01-14 18:12:43.683691 """ @@ -11,7 +11,7 @@ # revision identifiers, used by Alembic. revision = "fe03799b4018" -down_revision = "d25e7c47659e" +down_revision = "5163af6ba4a4" branch_labels = None depends_on = None diff --git a/frontend/src/views/OtherUses/OtherUsesSummary.jsx b/frontend/src/views/OtherUses/OtherUsesSummary.jsx index 7ae1b66e4..d89dbda78 100644 --- a/frontend/src/views/OtherUses/OtherUsesSummary.jsx +++ b/frontend/src/views/OtherUses/OtherUsesSummary.jsx @@ -89,7 +89,7 @@ export const OtherUsesSummary = ({ data, status }) => { minWidth: 200 }, { - headerName: t('otherUses:otherUsesColLabels.rationale'), + headerName: t('otherUses:otherUsesColLabels.otherExpectedUse'), field: 'rationale', floatingFilter: false, flex: 1,