From aa830be2e9aadc47fcbd28ef5c5687fe3e533f1e Mon Sep 17 00:00:00 2001 From: Kevin Hashimoto Date: Fri, 20 Dec 2024 10:44:42 -0800 Subject: [PATCH] fix: adjust line 1 and 2 calculations --- .../versions/2024-12-20-05-17_59873cafbcd8.py | 40 +++++++++++++++++++ .../db/seeders/common/seed_fuel_data.json | 6 +-- .../compliance_report/test_summary_service.py | 22 ++++++---- .../tests/fuel_code/test_fuel_code_repo.py | 35 ++++++++++------ .../test_notional_transfer_services.py | 19 +++++---- .../other_uses/test_other_uses_services.py | 31 +++++++++----- backend/lcfs/utils/constants.py | 12 ++++++ .../api/compliance_report/summary_service.py | 23 +++++++++-- .../web/api/notional_transfer/services.py | 17 ++++---- backend/lcfs/web/api/other_uses/services.py | 14 ++++--- 10 files changed, 163 insertions(+), 56 deletions(-) create mode 100644 backend/lcfs/db/migrations/versions/2024-12-20-05-17_59873cafbcd8.py diff --git a/backend/lcfs/db/migrations/versions/2024-12-20-05-17_59873cafbcd8.py b/backend/lcfs/db/migrations/versions/2024-12-20-05-17_59873cafbcd8.py new file mode 100644 index 000000000..79914e3b0 --- /dev/null +++ b/backend/lcfs/db/migrations/versions/2024-12-20-05-17_59873cafbcd8.py @@ -0,0 +1,40 @@ +"""update other diesel + +Revision ID: 59873cafbcd8 +Revises: 851e09cf8661 +Create Date: 2024-12-20 05:17:40.638826 + +""" + +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "59873cafbcd8" +down_revision = "851e09cf8661" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.execute( + """ + UPDATE fuel_type + SET fossil_derived = false, other_uses_fossil_derived = false + WHERE fuel_type = 'Other diesel' + """ + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.execute( + """ + UPDATE fuel_type + SET fossil_derived = true, other_uses_fossil_derived = true + WHERE fuel_type = 'Other diesel' + """ + ) + # ### end Alembic commands ### diff --git a/backend/lcfs/db/seeders/common/seed_fuel_data.json b/backend/lcfs/db/seeders/common/seed_fuel_data.json index c80c5f972..3584662f2 100644 --- a/backend/lcfs/db/seeders/common/seed_fuel_data.json +++ b/backend/lcfs/db/seeders/common/seed_fuel_data.json @@ -185,8 +185,8 @@ { "fuel_type_id": 20, "fuel_type": "Other diesel", - "fossil_derived": true, - "other_uses_fossil_derived": true, + "fossil_derived": false, + "other_uses_fossil_derived": false, "provision_1_id": 1, "default_carbon_intensity": 100.21, "units": "L", @@ -1095,4 +1095,4 @@ "display_order": 4 } ] -} +} \ No newline at end of file diff --git a/backend/lcfs/tests/compliance_report/test_summary_service.py b/backend/lcfs/tests/compliance_report/test_summary_service.py index 30cf918ef..dce14fef2 100644 --- a/backend/lcfs/tests/compliance_report/test_summary_service.py +++ b/backend/lcfs/tests/compliance_report/test_summary_service.py @@ -59,7 +59,8 @@ async def test_calculate_low_carbon_fuel_target_summary( # Assertions assert isinstance(summary, list) - assert all(isinstance(item, ComplianceReportSummaryRowSchema) for item in summary) + assert all(isinstance(item, ComplianceReportSummaryRowSchema) + for item in summary) assert len(summary) == 11 # Ensure all 11 lines are present # Check specific line values @@ -510,7 +511,8 @@ async def test_calculate_renewable_fuel_target_summary_no_renewables( assert len(result) == 11 assert isinstance(result[0], ComplianceReportSummaryRowSchema) - assert result[10].gasoline == 15.0 # Penalty should be applied due to no renewables + # Penalty should be applied due to no renewables + assert result[10].gasoline == 15.0 assert result[10].diesel == 36.0 assert result[10].jet_fuel == 45.0 assert result[10].total_value == 96.0 @@ -548,14 +550,12 @@ async def test_calculate_renewable_fuel_target_summary_high_renewables( assert len(result) == 11 assert isinstance(result[0], ComplianceReportSummaryRowSchema) - assert result[10].gasoline == 0 # No penalty since renewables exceed requirements + # No penalty since renewables exceed requirements + assert result[10].gasoline == 0 assert result[10].diesel == 0 assert result[10].jet_fuel == 0 -import pytest - - @pytest.mark.anyio async def test_calculate_renewable_fuel_target_summary_copy_lines_6_and_8( compliance_report_summary_service, @@ -710,6 +710,13 @@ async def test_can_sign_flag_logic( "jet_fuel": 25, } ) + mock_repo.aggregate_other_uses = AsyncMock( + return_value={ + "gasoline": 50, + "diesel": 25, + "jet_fuel": 10, + } + ) mock_repo.get_assessed_compliance_report_by_period = AsyncMock( return_value=MagicMock( summary=MagicMock( @@ -810,7 +817,8 @@ async def test_calculate_fuel_quantities_renewable( ): # Create a mock repository mock_repo.aggregate_fuel_supplies.return_value = {"gasoline": 200.0} - mock_repo.aggregate_other_uses.return_value = {"diesel": 75.0, "jet-fuel": 25.0} + mock_repo.aggregate_other_uses.return_value = { + "diesel": 75.0, "jet-fuel": 25.0} # Define test inputs compliance_report_id = 2 diff --git a/backend/lcfs/tests/fuel_code/test_fuel_code_repo.py b/backend/lcfs/tests/fuel_code/test_fuel_code_repo.py index 99bf2341d..2fdfc689b 100644 --- a/backend/lcfs/tests/fuel_code/test_fuel_code_repo.py +++ b/backend/lcfs/tests/fuel_code/test_fuel_code_repo.py @@ -158,7 +158,7 @@ async def test_get_fuel_categories(fuel_code_repo, mock_db): @pytest.mark.anyio -async def test_get_fuel_category_by_name(fuel_code_repo, mock_db): +async def test_get_fuel_category_by(fuel_code_repo, mock_db): mock_fc = FuelCategory( fuel_category_id=2, category="Fossil", default_carbon_intensity=0 ) @@ -327,7 +327,8 @@ async def test_get_fuel_codes_paginated(fuel_code_repo, mock_db): unique=MagicMock( return_value=MagicMock( scalars=MagicMock( - return_value=MagicMock(all=MagicMock(return_value=[fc])) + return_value=MagicMock( + all=MagicMock(return_value=[fc])) ) ) ) @@ -342,7 +343,8 @@ async def test_get_fuel_codes_paginated(fuel_code_repo, mock_db): @pytest.mark.anyio async def test_get_fuel_code_statuses(fuel_code_repo, mock_db): - fcs = FuelCodeStatus(fuel_code_status_id=1, status=FuelCodeStatusEnum.Approved) + fcs = FuelCodeStatus(fuel_code_status_id=1, + status=FuelCodeStatusEnum.Approved) mock_result = MagicMock() mock_result.scalars.return_value.all.return_value = [fcs] mock_db.execute.return_value = mock_result @@ -371,7 +373,8 @@ async def test_get_fuel_code(fuel_code_repo, mock_db, valid_fuel_code): @pytest.mark.anyio async def test_get_fuel_code_status_enum(fuel_code_repo, mock_db): - fcs = FuelCodeStatus(fuel_code_status_id=2, status=FuelCodeStatusEnum.Deleted) + fcs = FuelCodeStatus(fuel_code_status_id=2, + status=FuelCodeStatusEnum.Deleted) mock_db.scalar.return_value = fcs result = await fuel_code_repo.get_fuel_code_status(FuelCodeStatusEnum.Deleted) assert result == fcs @@ -403,7 +406,8 @@ async def test_delete_fuel_code(fuel_code_repo, mock_db): @pytest.mark.anyio async def test_get_distinct_company_names(fuel_code_repo, mock_db): mock_result = MagicMock() - mock_result.scalars.return_value.all.return_value = ["CompanyA", "CompanyB"] + mock_result.scalars.return_value.all.return_value = [ + "CompanyA", "CompanyB"] mock_db.execute.return_value = mock_result result = await fuel_code_repo.get_distinct_company_names("Com") @@ -413,7 +417,8 @@ async def test_get_distinct_company_names(fuel_code_repo, mock_db): @pytest.mark.anyio async def test_get_contact_names_by_company(fuel_code_repo, mock_db): mock_result = MagicMock() - mock_result.scalars.return_value.all.return_value = ["John Doe", "Jane Doe"] + mock_result.scalars.return_value.all.return_value = [ + "John Doe", "Jane Doe"] mock_db.execute.return_value = mock_result result = await fuel_code_repo.get_contact_names_by_company("CompanyA", "J") @@ -446,7 +451,8 @@ async def test_get_distinct_fuel_codes_by_code(fuel_code_repo, mock_db): async def test_get_fuel_code_by_code_prefix(fuel_code_repo, mock_db): fc = FuelCode(fuel_code_id=10, fuel_suffix="200.0") mock_result = MagicMock() - mock_result.unique.return_value.scalars.return_value.all.return_value = [fc] + mock_result.unique.return_value.scalars.return_value.all.return_value = [ + fc] mock_db.execute.return_value = mock_result # Mock the next available suffix @@ -612,7 +618,8 @@ async def test_get_standardized_fuel_data(fuel_code_repo, mock_db): MagicMock( scalars=MagicMock( return_value=MagicMock( - first=MagicMock(return_value=EnergyEffectivenessRatio(ratio=2.0)) + first=MagicMock( + return_value=EnergyEffectivenessRatio(ratio=2.0)) ) ) ), @@ -669,7 +676,8 @@ async def test_get_standardized_fuel_data_unrecognized(fuel_code_repo, mock_db): mock_db.get_one.return_value = mock_fuel_type # Mock the repo method to get the fuel category - fuel_code_repo.get_fuel_category_by = AsyncMock(return_value=mock_fuel_category) + fuel_code_repo.get_fuel_category_by = AsyncMock( + return_value=mock_fuel_category) # Setup side effects for subsequent queries: # Energy Density @@ -684,7 +692,8 @@ async def test_get_standardized_fuel_data_unrecognized(fuel_code_repo, mock_db): eer_result = MagicMock( scalars=MagicMock( return_value=MagicMock( - first=MagicMock(return_value=EnergyEffectivenessRatio(ratio=2.0)) + first=MagicMock( + return_value=EnergyEffectivenessRatio(ratio=2.0)) ) ) ) @@ -693,7 +702,8 @@ async def test_get_standardized_fuel_data_unrecognized(fuel_code_repo, mock_db): scalars=MagicMock( return_value=MagicMock( all=MagicMock( - return_value=[TargetCarbonIntensity(target_carbon_intensity=50.0)] + return_value=[TargetCarbonIntensity( + target_carbon_intensity=50.0)] ) ) ) @@ -729,7 +739,8 @@ async def test_get_standardized_fuel_data_unrecognized(fuel_code_repo, mock_db): assert result.uci == 5.0 # Ensure get_fuel_category_by was called once with the correct parameter - fuel_code_repo.get_fuel_category_by.assert_awaited_once_with(fuel_category_id=2) + fuel_code_repo.get_fuel_category_by.assert_awaited_once_with( + fuel_category_id=2) @pytest.mark.anyio diff --git a/backend/lcfs/tests/notional_transfer/test_notional_transfer_services.py b/backend/lcfs/tests/notional_transfer/test_notional_transfer_services.py index 073530a3b..cf8345153 100644 --- a/backend/lcfs/tests/notional_transfer/test_notional_transfer_services.py +++ b/backend/lcfs/tests/notional_transfer/test_notional_transfer_services.py @@ -21,7 +21,8 @@ def notional_transfer_service(): mock_repo = MagicMock(spec=NotionalTransferRepository) mock_fuel_repo = MagicMock() - service = NotionalTransferServices(repo=mock_repo, fuel_repo=mock_fuel_repo) + service = NotionalTransferServices( + repo=mock_repo, fuel_repo=mock_fuel_repo) return service, mock_repo, mock_fuel_repo @@ -47,12 +48,13 @@ async def test_get_table_options(notional_transfer_service): async def test_create_notional_transfer(notional_transfer_service): service, mock_repo, mock_fuel_repo = notional_transfer_service notional_transfer_data = create_mock_schema({}) - mock_fuel_repo.get_fuel_category_by_name = AsyncMock( + mock_fuel_repo.get_fuel_category_by = AsyncMock( return_value=MagicMock(fuel_category_id=1) ) mock_created_transfer = create_mock_entity({}) - mock_repo.create_notional_transfer = AsyncMock(return_value=mock_created_transfer) + mock_repo.create_notional_transfer = AsyncMock( + return_value=mock_created_transfer) response = await service.create_notional_transfer( notional_transfer_data, UserTypeEnum.SUPPLIER @@ -93,7 +95,7 @@ async def test_update_notional_transfer(notional_transfer_service): mock_repo.get_latest_notional_transfer_by_group_uuid = AsyncMock( return_value=mock_existing_transfer ) - mock_fuel_repo.get_fuel_category_by_name = AsyncMock( + mock_fuel_repo.get_fuel_category_by = AsyncMock( return_value=MagicMock(category="Gasoline") ) @@ -112,7 +114,8 @@ async def test_update_notional_transfer(notional_transfer_service): action_type=ActionTypeEnum.UPDATE, ) # Set the return value for update_notional_transfer - mock_repo.update_notional_transfer = AsyncMock(return_value=mock_updated_transfer) + mock_repo.update_notional_transfer = AsyncMock( + return_value=mock_updated_transfer) # Execute the update function and capture the response response = await service.update_notional_transfer( @@ -131,7 +134,8 @@ async def test_update_notional_transfer_not_found(notional_transfer_service): service, mock_repo, _ = notional_transfer_service notional_transfer_data = create_mock_schema({}) - mock_repo.get_notional_transfer_version_by_user = AsyncMock(return_value=None) + mock_repo.get_notional_transfer_version_by_user = AsyncMock( + return_value=None) with pytest.raises(ServiceException): await service.update_notional_transfer( @@ -171,7 +175,8 @@ async def test_delete_notional_transfer(notional_transfer_service): mock_repo.get_latest_notional_transfer_by_group_uuid = AsyncMock( return_value=mock_existing_transfer ) - mock_repo.create_notional_transfer = AsyncMock(return_value=mock_existing_transfer) + mock_repo.create_notional_transfer = AsyncMock( + return_value=mock_existing_transfer) # Call the delete service response = await service.delete_notional_transfer( diff --git a/backend/lcfs/tests/other_uses/test_other_uses_services.py b/backend/lcfs/tests/other_uses/test_other_uses_services.py index 14b3bb518..86794426a 100644 --- a/backend/lcfs/tests/other_uses/test_other_uses_services.py +++ b/backend/lcfs/tests/other_uses/test_other_uses_services.py @@ -66,11 +66,16 @@ async def test_create_other_use(other_uses_service): mock_fuel_code.fuel_code = "FuelCode123" # Mock fuel repository methods - mock_fuel_repo.get_fuel_category_by_name = AsyncMock(return_value=mock_fuel_category) - mock_fuel_repo.get_fuel_type_by_name = AsyncMock(return_value=mock_fuel_type) - mock_fuel_repo.get_expected_use_type_by_name = AsyncMock(return_value=mock_expected_use) - mock_fuel_repo.get_provision_of_the_act_by_name = AsyncMock(return_value=mock_provision_of_the_act) - mock_fuel_repo.get_fuel_code_by_name = AsyncMock(return_value=mock_fuel_code) + mock_fuel_repo.get_fuel_category_by = AsyncMock( + return_value=mock_fuel_category) + mock_fuel_repo.get_fuel_type_by_name = AsyncMock( + return_value=mock_fuel_type) + mock_fuel_repo.get_expected_use_type_by_name = AsyncMock( + return_value=mock_expected_use) + mock_fuel_repo.get_provision_of_the_act_by_name = AsyncMock( + return_value=mock_provision_of_the_act) + mock_fuel_repo.get_fuel_code_by_name = AsyncMock( + return_value=mock_fuel_code) # Create a mock for the created other use mock_created_use = create_mock_entity({}) @@ -115,7 +120,8 @@ async def test_update_other_use(other_uses_service): mock_existing_use = create_mock_entity({}) # Configure repository methods to return these mocked objects - mock_repo.get_other_use_version_by_user = AsyncMock(return_value=mock_existing_use) + mock_repo.get_other_use_version_by_user = AsyncMock( + return_value=mock_existing_use) # Mock related entities with proper string attributes mock_fuel_type = MagicMock() @@ -134,13 +140,17 @@ async def test_update_other_use(other_uses_service): mock_fuel_code.fuel_code = "NewFuelCode" # Mock fuel repository methods - mock_fuel_repo.get_fuel_type_by_name = AsyncMock(return_value=mock_fuel_type) - mock_fuel_repo.get_fuel_category_by_name = AsyncMock(return_value=mock_fuel_category) - mock_fuel_repo.get_expected_use_type_by_name = AsyncMock(return_value=mock_expected_use) + mock_fuel_repo.get_fuel_type_by_name = AsyncMock( + return_value=mock_fuel_type) + mock_fuel_repo.get_fuel_category_by = AsyncMock( + return_value=mock_fuel_category) + mock_fuel_repo.get_expected_use_type_by_name = AsyncMock( + return_value=mock_expected_use) mock_fuel_repo.get_provision_of_the_act_by_name = AsyncMock( return_value=mock_provision_of_the_act ) - mock_fuel_repo.get_fuel_code_by_name = AsyncMock(return_value=mock_fuel_code) + mock_fuel_repo.get_fuel_code_by_name = AsyncMock( + return_value=mock_fuel_code) # Mock the updated use returned after the update mock_updated_use = MagicMock() @@ -181,7 +191,6 @@ async def test_update_other_use(other_uses_service): mock_repo.update_other_use.assert_awaited_once() - @pytest.mark.anyio async def test_update_other_use_not_found(other_uses_service): service, mock_repo, _ = other_uses_service diff --git a/backend/lcfs/utils/constants.py b/backend/lcfs/utils/constants.py index 23d6752df..793fe2a4e 100644 --- a/backend/lcfs/utils/constants.py +++ b/backend/lcfs/utils/constants.py @@ -83,3 +83,15 @@ class FILE_MEDIA_TYPE(Enum): } default_ci = {"Gasoline": 93.67, "Diesel": 100.21, "Jet fuel": 88.83} + + +RENEWABLE_FUEL_TYPES = [ + "Renewable gasoline", + "Ethanol", + "Renewable naphtha", + "Biodiesel", + "HDRD", + "Other diesel", + "Alternative jet fuel", + "Other" +] diff --git a/backend/lcfs/web/api/compliance_report/summary_service.py b/backend/lcfs/web/api/compliance_report/summary_service.py index f241da143..c4a737c72 100644 --- a/backend/lcfs/web/api/compliance_report/summary_service.py +++ b/backend/lcfs/web/api/compliance_report/summary_service.py @@ -32,6 +32,8 @@ from lcfs.web.exception.exceptions import DataNotFoundException from lcfs.web.utils.calculations import calculate_compliance_units +from lcfs.utils.constants import RENEWABLE_FUEL_TYPES + logger = logging.getLogger(__name__) @@ -241,6 +243,12 @@ async def update_compliance_report_summary( return summary_data + def filter_renewable_fuel_supplies(self, fuel_supplies: List[FuelSupply]) -> List[FuelSupply]: + return [ + supply for supply in fuel_supplies + if supply.fuel_type and supply.fuel_type.fuel_type in RENEWABLE_FUEL_TYPES + ] + @service_handler async def calculate_compliance_report_summary( self, report_id: int @@ -326,14 +334,19 @@ async def calculate_compliance_report_summary( ) # Fetch fuel quantities + # line 1 fossil_quantities = await self.calculate_fuel_quantities( compliance_report.compliance_report_id, effective_fuel_supplies, fossil_derived=True ) + # line 2 + filtered_renewable_fuel_supplies = self.filter_renewable_fuel_supplies( + effective_fuel_supplies) + renewable_quantities = await self.calculate_fuel_quantities( compliance_report.compliance_report_id, - effective_fuel_supplies, + filtered_renewable_fuel_supplies, fossil_derived=False ) @@ -730,10 +743,14 @@ async def calculate_fuel_quantities( fuel_quantities = self.repo.aggregate_fuel_supplies( effective_fuel_supplies, fossil_derived ) - fuel_quantities.update( - await self.repo.aggregate_other_uses(compliance_report_id, fossil_derived) + + other_uses = await self.repo.aggregate_other_uses( + compliance_report_id, fossil_derived ) + for key, value in other_uses.items(): + fuel_quantities[key] = fuel_quantities.get(key, 0) + value + return dict(fuel_quantities) @service_handler diff --git a/backend/lcfs/web/api/notional_transfer/services.py b/backend/lcfs/web/api/notional_transfer/services.py index 4fdca07f4..207707bf6 100644 --- a/backend/lcfs/web/api/notional_transfer/services.py +++ b/backend/lcfs/web/api/notional_transfer/services.py @@ -50,12 +50,13 @@ async def convert_to_model( """ Converts data from NotionalTransferCreateSchema to NotionalTransfer data model to store into the database. """ - fuel_category = await self.fuel_repo.get_fuel_category_by_name( - notional_transfer_data.fuel_category + fuel_category = await self.fuel_repo.get_fuel_category_by( + category=notional_transfer_data.fuel_category ) return NotionalTransfer( **notional_transfer_data.model_dump( - exclude=NOTIONAL_TRANSFER_EXCLUDE_FIELDS.union({"fuel_category"}) + exclude=NOTIONAL_TRANSFER_EXCLUDE_FIELDS.union( + {"fuel_category"}) ), fuel_category_id=fuel_category.fuel_category_id, ) @@ -155,7 +156,8 @@ async def update_notional_transfer( ): # Update existing record if compliance report ID matches for field, value in notional_transfer_data.model_dump( - exclude=NOTIONAL_TRANSFER_EXCLUDE_FIELDS.union({"fuel_category"}) + exclude=NOTIONAL_TRANSFER_EXCLUDE_FIELDS.union( + {"fuel_category"}) ).items(): setattr(existing_transfer, field, value) @@ -164,8 +166,8 @@ async def update_notional_transfer( != notional_transfer_data.fuel_category ): existing_transfer.fuel_category = ( - await self.fuel_repo.get_fuel_category_by_name( - notional_transfer_data.fuel_category + await self.fuel_repo.get_fuel_category_by( + category=notional_transfer_data.fuel_category ) ) @@ -228,7 +230,8 @@ async def delete_notional_transfer( # Copy fields from the latest version for the deletion record for field in existing_transfer.__table__.columns.keys(): if field not in NOTIONAL_TRANSFER_EXCLUDE_FIELDS: - setattr(deleted_entity, field, getattr(existing_transfer, field)) + setattr(deleted_entity, field, getattr( + existing_transfer, field)) await self.repo.create_notional_transfer(deleted_entity) return DeleteNotionalTransferResponseSchema(message="Marked as deleted.") diff --git a/backend/lcfs/web/api/other_uses/services.py b/backend/lcfs/web/api/other_uses/services.py index 6fcc42f85..db5b22f81 100644 --- a/backend/lcfs/web/api/other_uses/services.py +++ b/backend/lcfs/web/api/other_uses/services.py @@ -52,8 +52,8 @@ async def schema_to_model(self, other_use: OtherUsesCreateSchema) -> OtherUses: """ Converts data from OtherUsesCreateSchema to OtherUses data model to store into the database. """ - fuel_category = await self.fuel_repo.get_fuel_category_by_name( - other_use.fuel_category + fuel_category = await self.fuel_repo.get_fuel_category_by( + category=other_use.fuel_category ) fuel_type = await self.fuel_repo.get_fuel_type_by_name(other_use.fuel_type) expected_use = await self.fuel_repo.get_expected_use_type_by_name( @@ -147,7 +147,8 @@ async def get_other_uses(self, compliance_report_id: int) -> OtherUsesListSchema """ other_uses = await self.repo.get_other_uses(compliance_report_id) return OtherUsesAllSchema( - other_uses=[OtherUsesSchema.model_validate(ou) for ou in other_uses] + other_uses=[OtherUsesSchema.model_validate( + ou) for ou in other_uses] ) @service_handler @@ -201,8 +202,8 @@ async def update_other_use( if other_use.fuel_category.category != other_use_data.fuel_category: other_use.fuel_category = ( - await self.fuel_repo.get_fuel_category_by_name( - other_use_data.fuel_category + await self.fuel_repo.get_fuel_category_by( + category=other_use_data.fuel_category ) ) @@ -290,7 +291,8 @@ async def delete_other_use( # Copy fields from the latest version for the deletion record for field in existing_fuel_supply.__table__.columns.keys(): if field not in OTHER_USE_EXCLUDE_FIELDS: - setattr(deleted_entity, field, getattr(existing_fuel_supply, field)) + setattr(deleted_entity, field, getattr( + existing_fuel_supply, field)) await self.repo.create_other_use(deleted_entity) return DeleteOtherUsesResponseSchema(success=True, message="Marked as deleted.")