Skip to content

Commit

Permalink
Added renewable naptha as a fuel code (#1779)
Browse files Browse the repository at this point in the history
  • Loading branch information
amichard authored Aug 31, 2021
1 parent 51d043b commit 065b204
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
77 changes: 77 additions & 0 deletions backend/api/fixtures/operational/0023_add_renewable_naptha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from django.db import transaction

from api.management.data_script import OperationalDataScript
from api.models.ApprovedFuel import ApprovedFuel
from api.models.DefaultCarbonIntensityCategory import \
DefaultCarbonIntensityCategory
from api.models.EnergyDensity import EnergyDensity
from api.models.EnergyDensityCategory import EnergyDensityCategory
from api.models.EnergyEffectivenessRatioCategory import \
EnergyEffectivenessRatioCategory
from api.models.UnitOfMeasure import UnitOfMeasure
from api.models.ApprovedFuelClass import ApprovedFuelClass
from api.models.FuelClass import FuelClass
from api.models.ApprovedFuelProvision import ApprovedFuelProvision


class AddRenewableNaptha(OperationalDataScript):
is_revertable = False
comment = 'Add renewable naptha as approved fuel'

def check_run_preconditions(self):
return True

@transaction.atomic
def run(self):
carbon_intensity_category = DefaultCarbonIntensityCategory.objects.filter(
name="Renewable fuel in relation to gasoline class fuel"
).first()
energy_density_category = EnergyDensityCategory.objects.create(
name="Naphtha produced from biomass",
display_order="11"
)
energy_density = EnergyDensity.objects.create(
category=energy_density_category,
density="32.76",
effective_date="2017-01-01"
)
energy_effective_ratio_category = EnergyEffectivenessRatioCategory.objects.get(
name="Petroleum-based gasoline, natural gas-based gasoline or renewable fuel in relation to gasoline class fuel"
)
unit_of_measure = UnitOfMeasure.objects.filter(
name="L"
).first()

fuel = ApprovedFuel.objects.create(
name="Renewable Naphtha",
description="Naphtha produced from biomass",
credit_calculation_only=False,
default_carbon_intensity_category=carbon_intensity_category,
energy_density_category=energy_density_category,
energy_effectiveness_ratio_category=energy_effective_ratio_category,
unit_of_measure=unit_of_measure,
is_partially_renewable=True
)

fuel_class = FuelClass.objects.filter(
fuel_class="Gasoline"
).first()

ApprovedFuelClass.objects.create(
fuel=fuel,
fuel_class=fuel_class
)

provisions = ApprovedFuelProvision.objects.filter(
fuel__name="Ethanol"
)

for provision in provisions:
ApprovedFuelProvision.objects.create(
fuel_id=fuel.id,
provision_act_id=provision.provision_act_id,
determination_type_id=provision.determination_type_id
)


script_class = AddRenewableNaptha
2 changes: 1 addition & 1 deletion backend/api/models/ComplianceReportSchedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def renewable_gasoline_volume(self):
self.fuel_code.renewable_percentage is not None:
fraction = self.fuel_code.renewable_percentage / decimal.Decimal(100.0)

renewable_fuels = ["Ethanol", "Renewable gasoline"]
renewable_fuels = ["Ethanol", "Renewable gasoline", "Renewable Naphtha"]
if self.fuel_type.name in renewable_fuels:
if self.fuel_class.fuel_class == 'Gasoline':
return self.quantity * fraction
Expand Down

0 comments on commit 065b204

Please sign in to comment.