Skip to content

Commit

Permalink
Update other_uses_fossil_derived in fuel_type table.
Browse files Browse the repository at this point in the history
  • Loading branch information
areyeslo committed Jan 14, 2025
1 parent c29ff14 commit a7aa3ed
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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'
)
""")
1 change: 1 addition & 0 deletions backend/lcfs/web/api/other_uses/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/views/OtherUses/AddEditOtherUses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a7aa3ed

Please sign in to comment.