From 767678a0a5ad782925a05a1ca63e2b740f5ff91d Mon Sep 17 00:00:00 2001 From: Daniel Haselhan Date: Tue, 17 Dec 2024 14:18:45 -0800 Subject: [PATCH] fix: Round all the things * Convert all column in summary that store quantity or units to integer as they should never have decimals * Update summary calculation to round unit penalties --- .../versions/2024-12-17-21-55_c1459274411a.py | 586 ++++++++++++++++++ .../compliance/ComplianceReportSummary.py | 91 +-- .../lcfs/web/api/compliance_report/repo.py | 8 +- .../api/compliance_report/summary_service.py | 7 +- 4 files changed, 642 insertions(+), 50 deletions(-) create mode 100644 backend/lcfs/db/migrations/versions/2024-12-17-21-55_c1459274411a.py diff --git a/backend/lcfs/db/migrations/versions/2024-12-17-21-55_c1459274411a.py b/backend/lcfs/db/migrations/versions/2024-12-17-21-55_c1459274411a.py new file mode 100644 index 000000000..9093b9f1d --- /dev/null +++ b/backend/lcfs/db/migrations/versions/2024-12-17-21-55_c1459274411a.py @@ -0,0 +1,586 @@ +"""Change Summary to Ints + +Revision ID: c1459274411a +Revises: 5b374dd97469 +Create Date: 2024-12-17 21:55:48.753760 + +""" + +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "c1459274411a" +down_revision = "5b374dd97469" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + "compliance_report_summary", + "line_1_fossil_derived_base_fuel_gasoline", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_1_fossil_derived_base_fuel_diesel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_1_fossil_derived_base_fuel_jet_fuel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_2_eligible_renewable_fuel_supplied_gasoline", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_2_eligible_renewable_fuel_supplied_diesel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_2_eligible_renewable_fuel_supplied_jet_fuel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_3_total_tracked_fuel_supplied_gasoline", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_3_total_tracked_fuel_supplied_diesel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_3_total_tracked_fuel_supplied_jet_fuel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_4_eligible_renewable_fuel_required_gasoline", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_4_eligible_renewable_fuel_required_diesel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_4_eligible_renewable_fuel_required_jet_fuel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_5_net_notionally_transferred_gasoline", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_5_net_notionally_transferred_diesel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_5_net_notionally_transferred_jet_fuel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_6_renewable_fuel_retained_gasoline", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_6_renewable_fuel_retained_diesel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_6_renewable_fuel_retained_jet_fuel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_7_previously_retained_gasoline", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_7_previously_retained_diesel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_7_previously_retained_jet_fuel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_8_obligation_deferred_gasoline", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_8_obligation_deferred_diesel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_8_obligation_deferred_jet_fuel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_9_obligation_added_gasoline", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_9_obligation_added_diesel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_9_obligation_added_jet_fuel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_10_net_renewable_fuel_supplied_gasoline", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_10_net_renewable_fuel_supplied_diesel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_10_net_renewable_fuel_supplied_jet_fuel", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_12_low_carbon_fuel_required", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_13_low_carbon_fuel_supplied", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_14_low_carbon_fuel_surplus", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_15_banked_units_used", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_16_banked_units_remaining", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_17_non_banked_units_used", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_18_units_to_be_banked", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_19_units_to_be_exported", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_20_surplus_deficit_units", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_22_compliance_units_issued", + existing_type=sa.DOUBLE_PRECISION(precision=53), + type_=sa.Integer(), + existing_nullable=False, + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + "compliance_report_summary", + "line_22_compliance_units_issued", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_20_surplus_deficit_units", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_19_units_to_be_exported", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_18_units_to_be_banked", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_17_non_banked_units_used", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_16_banked_units_remaining", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_15_banked_units_used", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_14_low_carbon_fuel_surplus", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_13_low_carbon_fuel_supplied", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_12_low_carbon_fuel_required", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_10_net_renewable_fuel_supplied_jet_fuel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_10_net_renewable_fuel_supplied_diesel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_10_net_renewable_fuel_supplied_gasoline", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_9_obligation_added_jet_fuel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_9_obligation_added_diesel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_9_obligation_added_gasoline", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_8_obligation_deferred_jet_fuel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_8_obligation_deferred_diesel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_8_obligation_deferred_gasoline", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_7_previously_retained_jet_fuel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_7_previously_retained_diesel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_7_previously_retained_gasoline", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_6_renewable_fuel_retained_jet_fuel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_6_renewable_fuel_retained_diesel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_6_renewable_fuel_retained_gasoline", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_5_net_notionally_transferred_jet_fuel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_5_net_notionally_transferred_diesel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_5_net_notionally_transferred_gasoline", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_4_eligible_renewable_fuel_required_jet_fuel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_4_eligible_renewable_fuel_required_diesel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_4_eligible_renewable_fuel_required_gasoline", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_3_total_tracked_fuel_supplied_jet_fuel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_3_total_tracked_fuel_supplied_diesel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_3_total_tracked_fuel_supplied_gasoline", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_2_eligible_renewable_fuel_supplied_jet_fuel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_2_eligible_renewable_fuel_supplied_diesel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_2_eligible_renewable_fuel_supplied_gasoline", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_1_fossil_derived_base_fuel_jet_fuel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_1_fossil_derived_base_fuel_diesel", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + op.alter_column( + "compliance_report_summary", + "line_1_fossil_derived_base_fuel_gasoline", + existing_type=sa.Integer(), + type_=sa.DOUBLE_PRECISION(precision=53), + existing_nullable=False, + ) + # ### end Alembic commands ### diff --git a/backend/lcfs/db/models/compliance/ComplianceReportSummary.py b/backend/lcfs/db/models/compliance/ComplianceReportSummary.py index 99b30b40d..f0552d01d 100644 --- a/backend/lcfs/db/models/compliance/ComplianceReportSummary.py +++ b/backend/lcfs/db/models/compliance/ComplianceReportSummary.py @@ -2,7 +2,6 @@ from sqlalchemy.exc import InvalidRequestError from sqlalchemy.orm import relationship from lcfs.db.base import BaseModel, Auditable -from datetime import datetime class ComplianceReportSummary(BaseModel, Auditable): @@ -19,70 +18,78 @@ class ComplianceReportSummary(BaseModel, Auditable): is_locked = Column(Boolean, default=False) # Renewable fuel target summary - line_1_fossil_derived_base_fuel_gasoline = Column(Float, nullable=False, default=0) - line_1_fossil_derived_base_fuel_diesel = Column(Float, nullable=False, default=0) - line_1_fossil_derived_base_fuel_jet_fuel = Column(Float, nullable=False, default=0) + line_1_fossil_derived_base_fuel_gasoline = Column( + Integer, nullable=False, default=0 + ) + line_1_fossil_derived_base_fuel_diesel = Column(Integer, nullable=False, default=0) + line_1_fossil_derived_base_fuel_jet_fuel = Column( + Integer, nullable=False, default=0 + ) line_2_eligible_renewable_fuel_supplied_gasoline = Column( - Float, nullable=False, default=0 + Integer, nullable=False, default=0 ) line_2_eligible_renewable_fuel_supplied_diesel = Column( - Float, nullable=False, default=0 + Integer, nullable=False, default=0 ) line_2_eligible_renewable_fuel_supplied_jet_fuel = Column( - Float, nullable=False, default=0 + Integer, nullable=False, default=0 ) line_3_total_tracked_fuel_supplied_gasoline = Column( - Float, nullable=False, default=0 + Integer, nullable=False, default=0 + ) + line_3_total_tracked_fuel_supplied_diesel = Column( + Integer, nullable=False, default=0 ) - line_3_total_tracked_fuel_supplied_diesel = Column(Float, nullable=False, default=0) line_3_total_tracked_fuel_supplied_jet_fuel = Column( - Float, nullable=False, default=0 + Integer, nullable=False, default=0 ) line_4_eligible_renewable_fuel_required_gasoline = Column( - Float, nullable=False, default=0 + Integer, nullable=False, default=0 ) line_4_eligible_renewable_fuel_required_diesel = Column( - Float, nullable=False, default=0 + Integer, nullable=False, default=0 ) line_4_eligible_renewable_fuel_required_jet_fuel = Column( - Float, nullable=False, default=0 + Integer, nullable=False, default=0 ) line_5_net_notionally_transferred_gasoline = Column( - Float, nullable=False, default=0 + Integer, nullable=False, default=0 + ) + line_5_net_notionally_transferred_diesel = Column( + Integer, nullable=False, default=0 ) - line_5_net_notionally_transferred_diesel = Column(Float, nullable=False, default=0) line_5_net_notionally_transferred_jet_fuel = Column( - Float, nullable=False, default=0 + Integer, nullable=False, default=0 ) - line_6_renewable_fuel_retained_gasoline = Column(Float, nullable=False, default=0) - line_6_renewable_fuel_retained_diesel = Column(Float, nullable=False, default=0) - line_6_renewable_fuel_retained_jet_fuel = Column(Float, nullable=False, default=0) + line_6_renewable_fuel_retained_gasoline = Column(Integer, nullable=False, default=0) + line_6_renewable_fuel_retained_diesel = Column(Integer, nullable=False, default=0) + line_6_renewable_fuel_retained_jet_fuel = Column(Integer, nullable=False, default=0) - line_7_previously_retained_gasoline = Column(Float, nullable=False, default=0) - line_7_previously_retained_diesel = Column(Float, nullable=False, default=0) - line_7_previously_retained_jet_fuel = Column(Float, nullable=False, default=0) + line_7_previously_retained_gasoline = Column(Integer, nullable=False, default=0) + line_7_previously_retained_diesel = Column(Integer, nullable=False, default=0) + line_7_previously_retained_jet_fuel = Column(Integer, nullable=False, default=0) - line_8_obligation_deferred_gasoline = Column(Float, nullable=False, default=0) - line_8_obligation_deferred_diesel = Column(Float, nullable=False, default=0) - line_8_obligation_deferred_jet_fuel = Column(Float, nullable=False, default=0) + line_8_obligation_deferred_gasoline = Column(Integer, nullable=False, default=0) + line_8_obligation_deferred_diesel = Column(Integer, nullable=False, default=0) + line_8_obligation_deferred_jet_fuel = Column(Integer, nullable=False, default=0) - line_9_obligation_added_gasoline = Column(Float, nullable=False, default=0) - line_9_obligation_added_diesel = Column(Float, nullable=False, default=0) - line_9_obligation_added_jet_fuel = Column(Float, nullable=False, default=0) + line_9_obligation_added_gasoline = Column(Integer, nullable=False, default=0) + line_9_obligation_added_diesel = Column(Integer, nullable=False, default=0) + line_9_obligation_added_jet_fuel = Column(Integer, nullable=False, default=0) line_10_net_renewable_fuel_supplied_gasoline = Column( - Float, nullable=False, default=0 + Integer, nullable=False, default=0 ) line_10_net_renewable_fuel_supplied_diesel = Column( - Float, nullable=False, default=0 + Integer, nullable=False, default=0 ) line_10_net_renewable_fuel_supplied_jet_fuel = Column( - Float, nullable=False, default=0 + Integer, nullable=False, default=0 ) line_11_non_compliance_penalty_gasoline = Column(Float, nullable=True, default=0) @@ -90,17 +97,17 @@ class ComplianceReportSummary(BaseModel, Auditable): line_11_non_compliance_penalty_jet_fuel = Column(Float, nullable=True, default=0) # Low carbon fuel target summary columns - line_12_low_carbon_fuel_required = Column(Float, nullable=False, default=0) - line_13_low_carbon_fuel_supplied = Column(Float, nullable=False, default=0) - line_14_low_carbon_fuel_surplus = Column(Float, nullable=False, default=0) - line_15_banked_units_used = Column(Float, nullable=False, default=0) - line_16_banked_units_remaining = Column(Float, nullable=False, default=0) - line_17_non_banked_units_used = Column(Float, nullable=False, default=0) - line_18_units_to_be_banked = Column(Float, nullable=False, default=0) - line_19_units_to_be_exported = Column(Float, nullable=False, default=0) - line_20_surplus_deficit_units = Column(Float, nullable=False, default=0) + line_12_low_carbon_fuel_required = Column(Integer, nullable=False, default=0) + line_13_low_carbon_fuel_supplied = Column(Integer, nullable=False, default=0) + line_14_low_carbon_fuel_surplus = Column(Integer, nullable=False, default=0) + line_15_banked_units_used = Column(Integer, nullable=False, default=0) + line_16_banked_units_remaining = Column(Integer, nullable=False, default=0) + line_17_non_banked_units_used = Column(Integer, nullable=False, default=0) + line_18_units_to_be_banked = Column(Integer, nullable=False, default=0) + line_19_units_to_be_exported = Column(Integer, nullable=False, default=0) + line_20_surplus_deficit_units = Column(Integer, nullable=False, default=0) line_21_surplus_deficit_ratio = Column(Float, nullable=False, default=0) - line_22_compliance_units_issued = Column(Float, nullable=False, default=0) + line_22_compliance_units_issued = Column(Integer, nullable=False, default=0) # Non-compliance penalty summary columns line_11_fossil_derived_base_fuel_gasoline = Column(Float, nullable=False, default=0) @@ -121,4 +128,4 @@ def lock_summary(self): def __repr__(self): return f"" - # method to annualize a report once all four quarters are approved? \ No newline at end of file + # method to annualize a report once all four quarters are approved? diff --git a/backend/lcfs/web/api/compliance_report/repo.py b/backend/lcfs/web/api/compliance_report/repo.py index 1bac62843..525dd172c 100644 --- a/backend/lcfs/web/api/compliance_report/repo.py +++ b/backend/lcfs/web/api/compliance_report/repo.py @@ -706,9 +706,9 @@ async def get_issued_compliance_units( def aggregate_fuel_supplies( self, fuel_supplies: List[FuelSupply], fossil_derived: bool - ) -> Dict[str, float]: + ) -> Dict[str, int]: """Aggregate quantities from fuel supplies based on fossil_derived flag.""" - fuel_quantities = defaultdict(float) + fuel_quantities = defaultdict(int) # Use a list comprehension to filter and iterate in one step for fs in ( @@ -722,7 +722,7 @@ def aggregate_fuel_supplies( @repo_handler async def aggregate_other_uses( self, compliance_report_id: int, fossil_derived: bool - ) -> Dict[str, float]: + ) -> Dict[str, int]: """Aggregate quantities from other uses.""" query = ( select( @@ -751,7 +751,7 @@ async def aggregate_other_uses( @repo_handler async def aggregate_allocation_agreements( self, compliance_report_id: int - ) -> Dict[str, float]: + ) -> Dict[str, int]: """Aggregate quantities from allocation agreements for renewable fuels.""" query = ( select( diff --git a/backend/lcfs/web/api/compliance_report/summary_service.py b/backend/lcfs/web/api/compliance_report/summary_service.py index f241da143..fb216652b 100644 --- a/backend/lcfs/web/api/compliance_report/summary_service.py +++ b/backend/lcfs/web/api/compliance_report/summary_service.py @@ -408,7 +408,6 @@ def map_to_schema( compliance_report_id=compliance_report.compliance_report_id, is_locked=summary_model.is_locked, quarter=summary_model.quarter, - total_non_compliance_penalty_payable=summary_model.total_non_compliance_penalty_payable, renewable_fuel_target_summary=renewable_fuel_target_summary, low_carbon_fuel_target_summary=low_carbon_fuel_target_summary, non_compliance_penalty_summary=non_compliance_penalty_summary, @@ -444,9 +443,9 @@ def calculate_renewable_fuel_target_summary( jet_fuel_percentage = 3 / 100 eligible_renewable_fuel_required = { - "gasoline": tracked_totals["gasoline"] * 0.05, - "diesel": tracked_totals["diesel"] * 0.04, - "jet_fuel": tracked_totals["jet_fuel"] * jet_fuel_percentage, + "gasoline": round(tracked_totals["gasoline"] * 0.05), + "diesel": round(tracked_totals["diesel"] * 0.04), + "jet_fuel": round(tracked_totals["jet_fuel"] * jet_fuel_percentage), } # line 6