Skip to content

Commit

Permalink
Merge branch 'release-0.2.0' into fix/hamed-decimal-formatting-bceid-…
Browse files Browse the repository at this point in the history
…1529
  • Loading branch information
hamed-valiollahi authored Jan 7, 2025
2 parents 2e24197 + 9ec582f commit ed4374a
Show file tree
Hide file tree
Showing 83 changed files with 1,346 additions and 987 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def upgrade() -> None:
(20, 'Compression-ignition engine- Marine, with methane slip reduction kit- Operated within 76 to 100% of load range', TRUE),
(21, 'Compression-ignition engine- Marine, unknown whether kit is installed or average operating load range', TRUE),
(22, 'Unknown engine type', TRUE),
(23, 'Other (i.e. road transportation)', TRUE)
(23, 'Other (i.e. road transportation)', TRUE),
(24, 'Any', TRUE)
ON CONFLICT (end_use_type_id) DO NOTHING;
""")
Expand Down Expand Up @@ -224,13 +225,13 @@ def upgrade() -> None:
eer_id, fuel_category_id, fuel_type_id, end_use_type_id, ratio, effective_status
)
VALUES
(1, 1, 2, NULL, 0.9, TRUE),
(1, 1, 2, 24, 0.9, TRUE),
(2, 1, 3, 1, 3.5, TRUE),
(3, 1, 3, 2, 1.0, TRUE),
(4, 1, 6, 3, 2.4, TRUE),
(5, 1, 6, 2, 0.9, TRUE),
(6, 1, 13, NULL, 0.9, TRUE),
(7, 2, 2, NULL, 0.9, TRUE),
(6, 1, 13, 24, 0.9, TRUE),
(7, 2, 2, 24, 0.9, TRUE),
(8, 2, 3, 4, 3.8, TRUE),
(9, 2, 3, 5, 3.2, TRUE),
(10, 2, 3, 6, 2.5, TRUE),
Expand All @@ -242,9 +243,9 @@ def upgrade() -> None:
(16, 2, 3, 2, 1.0, TRUE),
(17, 2, 6, 3, 1.8, TRUE),
(18, 2, 6, 2, 0.9, TRUE),
(19, 2, 13, NULL, 0.9, TRUE),
(20, 3, 3, NULL, 2.5, TRUE),
(21, 3, 11, NULL, 1.0, TRUE),
(19, 2, 13, 24, 0.9, TRUE),
(20, 3, 3, 24, 2.5, TRUE),
(21, 3, 11, 24, 1.0, TRUE),
(22, 2, 7, 15, 1.0, TRUE),
(23, 2, 7, 16, 1.0, TRUE),
(24, 2, 7, 17, 1.0, TRUE),
Expand All @@ -253,7 +254,20 @@ def upgrade() -> None:
(27, 2, 7, 20, 1.0, TRUE),
(28, 2, 7, 21, 1.0, TRUE),
(29, 2, 7, 22, 0.9, TRUE),
(30, 2, 7, 23, 0.9, TRUE)
(30, 2, 7, 23, 0.9, TRUE),
(31, 2, 1, 24, 1.0, TRUE),
(32, 2, 5, 24, 1.0, TRUE),
(33, 3, 6, 24, 1.0, TRUE),
(34, 1, 14, 24, 1.0, TRUE),
(35, 1, 15, 24, 1.0, TRUE),
(36, 2, 16, 24, 1.0, TRUE),
(37, 1, 17, 24, 1.0, TRUE),
(38, 3, 18, 24, 1.0, TRUE),
(39, 1, 19, 24, 1.0, TRUE),
(40, 2, 19, 24, 1.0, TRUE),
(41, 3, 7, 24, 1.0, TRUE),
(42, 2, 20, 24, 1.0, TRUE),
(43, 1, 4, 24, 1.0, TRUE)
ON CONFLICT (eer_id) DO NOTHING;
""")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""Rename Reassessed
Revision ID: e883ad1f0f60
Revises: 9329e38396e1
Create Date: 2025-01-03 23:31:19.098618
"""

import sqlalchemy as sa
from alembic import op
from alembic_postgresql_enum import TableReference

# revision identifiers, used by Alembic.
revision = "e883ad1f0f60"
down_revision = "9329e38396e1"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.sync_enum_values(
"public",
"compliancereportstatusenum",
[
"Draft",
"Submitted",
"Recommended_by_analyst",
"Recommended_by_manager",
"Assessed",
"Reassessed",
],
[
TableReference(
table_schema="public",
table_name="compliance_report_status",
column_name="status",
)
],
enum_values_to_rename=[("ReAssessed", "Reassessed")],
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.sync_enum_values(
"public",
"compliancereportstatusenum",
[
"Draft",
"Submitted",
"Recommended_by_analyst",
"Recommended_by_manager",
"Assessed",
"ReAssessed",
],
[
TableReference(
table_schema="public",
table_name="compliance_report_status",
column_name="status",
)
],
enum_values_to_rename=[("Reassessed", "ReAssessed")],
)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Update fuel type name
Revision ID: bfa7bbb1eea3
Revises: 9329e38396e1
Create Date: 2025-01-03 13:24:19.525006
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "bfa7bbb1eea3"
down_revision = "e883ad1f0f60"
branch_labels = None
depends_on = None


def upgrade() -> None:
# Update fuel type name
op.execute("""
UPDATE fuel_type
SET fuel_type = 'Other diesel fuel',
provision_1_id = 3 -- Change from prescribed (1) to default (3)
WHERE fuel_type = 'Other diesel';
""")


def downgrade() -> None:
# Revert fuel type name update
op.execute("""
UPDATE fuel_type
SET fuel_type = 'Other diesel',
provision_1_id = 1 -- Change from default (3) to prescribed (1)
WHERE fuel_type = 'Other diesel fuel';
""")

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Add is_legacy to fuel_type
Revision ID: ca7200152130
Revises: bfa7bbb1eea3
Create Date: 2025-01-05 18:43:43.638740
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "ca7200152130"
down_revision = "bfa7bbb1eea3"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"fuel_type",
sa.Column(
"is_legacy",
sa.Boolean(),
server_default=sa.text("FALSE"),
nullable=False,
comment="Indicates if the fuel type is legacy and should not be used for new reports",
),
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("fuel_type", "is_legacy")
# ### end Alembic commands ###
125 changes: 125 additions & 0 deletions backend/lcfs/db/migrations/versions/2025-01-06-19-01_94306eca5261.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
"""
Add is_legacy to Provisions and insert data
Revision ID: 94306eca5261
Revises: ca7200152130
Create Date: 2025-01-06 19:01:53.418638
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "94306eca5261"
down_revision = "ca7200152130"
branch_labels = None
depends_on = None


def upgrade() -> None:
# 1) Add the new column
op.add_column(
"provision_of_the_act",
sa.Column(
"is_legacy",
sa.Boolean(),
server_default=sa.text("FALSE"),
nullable=False,
comment="Indicates if the provision is legacy and should not be used for new reports",
),
)

# 2) Insert or update data to populate is_legacy, etc.
# For demonstration, we'll use bulk_insert here. If your table already
# has data, you might prefer an UPDATE or a combination of both.
provision_of_the_act = sa.Table(
"provision_of_the_act",
sa.MetaData(),
sa.Column("provision_of_the_act_id", sa.Integer, primary_key=True),
sa.Column("name", sa.String),
sa.Column("description", sa.String),
sa.Column("create_user", sa.String),
sa.Column("update_user", sa.String),
sa.Column("display_order", sa.Integer),
sa.Column("effective_date", sa.Date),
sa.Column("effective_status", sa.Boolean),
sa.Column("expiration_date", sa.Date),
sa.Column("is_legacy", sa.Boolean),
)

op.bulk_insert(
provision_of_the_act,
[
{
"name": "Prescribed carbon intensity - Section 6 (5) (a)",
"description": "Prescribed carbon intensity - Section 6 (5) (a)",
"create_user": "no_user",
"update_user": "no_user",
"display_order": None,
"effective_date": None,
"effective_status": True,
"expiration_date": None,
"is_legacy": True,
},
{
"name": "Prescribed carbon intensity - Section 6 (5) (b)",
"description": "Prescribed carbon intensity - Section 6 (5) (b)",
"create_user": "no_user",
"update_user": "no_user",
"display_order": None,
"effective_date": None,
"effective_status": True,
"expiration_date": None,
"is_legacy": True,
},
{
"name": "Approved fuel code - Section 6 (5) (c)",
"description": "Approved fuel code - Section 6 (5) (c)",
"create_user": "no_user",
"update_user": "no_user",
"display_order": None,
"effective_date": None,
"effective_status": True,
"expiration_date": None,
"is_legacy": True,
},
{
"name": "Default Carbon Intensity Value - Section 6 (5) (d) (i)",
"description": "Default Carbon Intensity Value - Section 6 (5) (d) (i)",
"create_user": "no_user",
"update_user": "no_user",
"display_order": None,
"effective_date": None,
"effective_status": True,
"expiration_date": None,
"is_legacy": True,
},
{
"name": "GHGenius modelled - Section 6 (5) (d) (ii) (A)",
"description": "GHGenius modelled - Section 6 (5) (d) (ii) (A)",
"create_user": "no_user",
"update_user": "no_user",
"display_order": None,
"effective_date": None,
"effective_status": True,
"expiration_date": None,
"is_legacy": True,
},
{
"name": "Alternative Method - Section 6 (5) (d) (ii) (B)",
"description": "Alternative Method - Section 6 (5) (d) (ii) (B)",
"create_user": "no_user",
"update_user": "no_user",
"display_order": None,
"effective_date": None,
"effective_status": True,
"expiration_date": None,
"is_legacy": True,
},
],
)


def downgrade() -> None:
# Remove is_legacy column. (Data removal is optional or up to you.)
op.drop_column("provision_of_the_act", "is_legacy")
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ComplianceReportStatusEnum(enum.Enum):
Recommended_by_analyst = "Recommended by analyst"
Recommended_by_manager = "Recommended by manager"
Assessed = "Assessed"
ReAssessed = "ReAssessed"
Reassessed = "Reassessed"


class ComplianceReportStatus(BaseModel, EffectiveDates):
Expand Down
8 changes: 7 additions & 1 deletion backend/lcfs/db/models/fuel/FuelType.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import enum

from sqlalchemy import Column, Integer, Text, Boolean, Enum, Numeric
from sqlalchemy import Column, Integer, Text, Boolean, Enum, Numeric, text
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship

Expand Down Expand Up @@ -54,6 +54,12 @@ class FuelType(BaseModel, Auditable, DisplayOrder):
nullable=False,
comment="Indicates if the fuel type is unrecognized",
)
is_legacy = Column(
Boolean,
server_default=text("FALSE"),
nullable=False,
comment="Indicates if the fuel type is legacy and should not be used for new reports",
)

# Relationships
fuel_codes = relationship("FuelCode", back_populates="fuel_type")
Expand Down
8 changes: 7 additions & 1 deletion backend/lcfs/db/models/fuel/ProvisionOfTheAct.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy import Column, Integer, String, Boolean
from sqlalchemy import Column, Integer, String, Boolean, text
from sqlalchemy.orm import relationship
from lcfs.db.base import BaseModel, Auditable, DisplayOrder, EffectiveDates

Expand Down Expand Up @@ -28,6 +28,12 @@ class ProvisionOfTheAct(BaseModel, Auditable, DisplayOrder, EffectiveDates):
nullable=False,
comment="Description of the provision. This is the displayed name. e.g. Prescribed Carbon Intensity, Approved Fuel Code.",
)
is_legacy = Column(
Boolean,
server_default=text("FALSE"),
nullable=False,
comment="Indicates if the fuel type is legacy and should not be used for new reports",
)

# relationships
fuel_type_provision_1 = relationship(
Expand Down
4 changes: 3 additions & 1 deletion backend/lcfs/tests/fuel_supply/test_fuel_supplies_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async def test_check_duplicate(fuel_supply_repo, mock_db_session):
compliance_report_id=1,
fuel_type_id=1,
fuel_category_id=1,
end_use_id=24,
provision_of_the_act_id=1,
quantity=1000,
units="L",
Expand All @@ -82,7 +83,8 @@ async def test_check_duplicate(fuel_supply_repo, mock_db_session):
# Set up the mock chain using regular MagicMock since the chained methods are sync
mock_result_chain = MagicMock()
mock_result_chain.scalars = MagicMock(return_value=mock_result_chain)
mock_result_chain.first = MagicMock(return_value=MagicMock(spec=FuelSupply))
mock_result_chain.first = MagicMock(
return_value=MagicMock(spec=FuelSupply))

# Define an async execute function that returns our mock chain
async def mock_execute(*args, **kwargs):
Expand Down
Loading

0 comments on commit ed4374a

Please sign in to comment.