def create_compliance_period() -> dict: """Create a test compliance period""" cp = CompliancePeriod() cp.description = 'Compliance Period {0!s}'.format(uuid.uuid4()) cp.display_order = 1 cp.save() cp.refresh_from_db() return {'id': cp.id}
def run(self): compliance_periods = [] display_order = 10 for period in range(2021, 2031): display_order += 1 compliance_periods.append( CompliancePeriod(description=period, display_order=display_order, effective_date="{}-01-01".format(period), expiration_date="{}-12-31".format(period))) CompliancePeriod.objects.bulk_create(compliance_periods)
def run(self): CompliancePeriod( description='2018', display_order=2, effective_date=datetime.today().strftime('%Y-%m-%d')).save() Organization( name=self._orgs[0], actions_type=OrganizationActionsType.objects.get_by_natural_key( "Buy And Sell"), type=OrganizationType.objects.get_by_natural_key( "Part3FuelSupplier"), status=OrganizationStatus.objects.get_by_natural_key('Active'), id=2).save() Organization( name=self._orgs[1], actions_type=OrganizationActionsType.objects.get_by_natural_key( "Buy And Sell"), type=OrganizationType.objects.get_by_natural_key( "Part3FuelSupplier"), status=OrganizationStatus.objects.get_by_natural_key('Active'), id=3).save() Organization( name=self._orgs[2], actions_type=OrganizationActionsType.objects.get_by_natural_key( "Buy And Sell"), type=OrganizationType.objects.get_by_natural_key( "Part3FuelSupplier"), status=OrganizationStatus.objects.get_by_natural_key('Active'), id=4).save() OrganizationBalance( organization=Organization.objects.get_by_natural_key( self._orgs[0]), credit_trade=None, validated_credits=1000, effective_date=datetime.today().strftime('%Y-%m-%d')).save() OrganizationBalance( organization=Organization.objects.get_by_natural_key( self._orgs[1]), credit_trade=None, validated_credits=1000, effective_date=datetime.today().strftime('%Y-%m-%d')).save() OrganizationBalance( organization=Organization.objects.get_by_natural_key( self._orgs[2]), credit_trade=None, validated_credits=1000, effective_date=datetime.today().strftime('%Y-%m-%d')).save() User(email='*****@*****.**', authorization_guid=uuid.uuid4(), username='******', authorization_id='fs1', first_name='FS1', last_name='Supplier', display_name='Fuel Supplier', authorization_directory='BCeID', organization=Organization.objects.get_by_natural_key( self._orgs[0])).save() User(email='*****@*****.**', authorization_guid=uuid.uuid4(), username='******', authorization_id='fs2', first_name='FS2', last_name='Supplier', display_name='Another Fuel Supplier', authorization_directory='BCeID', organization=Organization.objects.get_by_natural_key( self._orgs[1])).save() User(email='*****@*****.**', authorization_guid=uuid.uuid4(), username='******', authorization_id='fs3', first_name='FS3', last_name='Supplier', display_name='Third Fuel Supplier', authorization_directory='BCeID', organization=Organization.objects.get_by_natural_key( self._orgs[2])).save() User(email='*****@*****.**', authorization_guid=uuid.uuid4(), username='******', authorization_id='analyst', first_name='Analyst', last_name='Government', display_name='(Analyst)', authorization_directory='IDIR', organization=Organization.objects.get(id=1)).save() User(email='*****@*****.**', authorization_guid=uuid.uuid4(), username='******', authorization_id='director', first_name='Director', last_name='Government', display_name='(Director)', authorization_directory='IDIR', organization=Organization.objects.get(id=1)).save() User(email='*****@*****.**', authorization_guid=uuid.uuid4(), username='******', authorization_id='tfrsadmin', first_name='TfrsAdmin', last_name='Government', display_name='(TfrsAdmin)', authorization_directory='IDIR', organization=Organization.objects.get(id=1)).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('FSManager')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('FSManager')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('FSManager')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('FSAdmin')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('GovUser')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('GovDirector')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('Admin')).save() self.dump_nginx_config()
def run(self): CompliancePeriod.objects.get( description='Auto-generated initial compliance period').delete() display_order = 10 compliance_periods = [] for period in range(2013, 2031): display_order += 1 compliance_periods.append( CompliancePeriod(description=period, display_order=display_order, effective_date="{}-01-01".format(period), expiration_date="{}-12-31".format(period))) CompliancePeriod.objects.bulk_create(compliance_periods) Organization( name=self._orgs[0], actions_type=OrganizationActionsType.objects.get_by_natural_key( "Buy And Sell"), type=OrganizationType.objects.get_by_natural_key( "Part3FuelSupplier"), status=OrganizationStatus.objects.get_by_natural_key('Active'), id=2).save() Organization( name=self._orgs[1], actions_type=OrganizationActionsType.objects.get_by_natural_key( "Buy And Sell"), type=OrganizationType.objects.get_by_natural_key( "Part3FuelSupplier"), status=OrganizationStatus.objects.get_by_natural_key('Active'), id=3).save() Organization( name=self._orgs[2], actions_type=OrganizationActionsType.objects.get_by_natural_key( "Buy And Sell"), type=OrganizationType.objects.get_by_natural_key( "Part3FuelSupplier"), status=OrganizationStatus.objects.get_by_natural_key('Active'), id=4).save() OrganizationBalance( organization=Organization.objects.get_by_natural_key( self._orgs[0]), credit_trade=None, validated_credits=1000, effective_date=datetime.today().strftime('%Y-%m-%d')).save() OrganizationBalance( organization=Organization.objects.get_by_natural_key( self._orgs[1]), credit_trade=None, validated_credits=1000, effective_date=datetime.today().strftime('%Y-%m-%d')).save() OrganizationBalance( organization=Organization.objects.get_by_natural_key( self._orgs[2]), credit_trade=None, validated_credits=1000, effective_date=datetime.today().strftime('%Y-%m-%d')).save() User(email='*****@*****.**', username='******', first_name='FS1', last_name='Supplier', display_name='Fuel Supplier', organization=Organization.objects.get_by_natural_key( self._orgs[0])).save() User(email='*****@*****.**', username='******', first_name='FS2', last_name='Supplier', display_name='Another Fuel Supplier', organization=Organization.objects.get_by_natural_key( self._orgs[1])).save() User(email='*****@*****.**', username='******', first_name='FS3', last_name='Supplier', display_name='Third Fuel Supplier', organization=Organization.objects.get_by_natural_key( self._orgs[2])).save() User(email='*****@*****.**', username='******', first_name='Analyst', last_name='Government', display_name='Analyst', organization=Organization.objects.get(id=1)).save() User(email='*****@*****.**', username='******', first_name='Director', last_name='Government', display_name='(Director)', organization=Organization.objects.get(id=1)).save() User(email='*****@*****.**', username='******', first_name='TfrsAdmin', last_name='Government', display_name='(TfrsAdmin)', organization=Organization.objects.get(id=1)).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('FSManager')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key( 'ComplianceReporting')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('FSDocSubmit')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('FSManager')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('FSDocSubmit')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('FSManager')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('FSDocSubmit')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('FSAdmin')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('GovUser')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('GovDoc')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('GovDirector')).save() UserRole(user=User.objects.get(username='******'), role=Role.objects.get_by_natural_key('Admin')).save() # These are copied verbatim from operational scripts 0006 through 0012. # They must be copied instead of run on startup since their precondition checks don't do anything CarbonIntensityLimit.objects.create( compliance_period=CompliancePeriod.objects.get(description="2017"), effective_date="2017-01-01", expiration_date="2017-12-31", density="90.02", fuel_class=FuelClass.objects.get(fuel_class="Diesel")) CarbonIntensityLimit.objects.create( compliance_period=CompliancePeriod.objects.get(description="2017"), effective_date="2017-01-01", expiration_date="2017-12-31", density="83.74", fuel_class=FuelClass.objects.get(fuel_class="Gasoline")) # 2018 CarbonIntensityLimit.objects.create( compliance_period=CompliancePeriod.objects.get(description="2018"), effective_date="2018-01-01", expiration_date="2018-12-31", density="88.60", fuel_class=FuelClass.objects.get(fuel_class="Diesel")) CarbonIntensityLimit.objects.create( compliance_period=CompliancePeriod.objects.get(description="2018"), effective_date="2018-01-01", expiration_date="2018-12-31", density="82.41", fuel_class=FuelClass.objects.get(fuel_class="Gasoline")) # 2019 CarbonIntensityLimit.objects.create( compliance_period=CompliancePeriod.objects.get(description="2019"), effective_date="2019-01-01", expiration_date="2019-12-31", density="87.18", fuel_class=FuelClass.objects.get(fuel_class="Diesel")) CarbonIntensityLimit.objects.create( compliance_period=CompliancePeriod.objects.get(description="2019"), effective_date="2019-01-01", expiration_date="2019-12-31", density="81.09", fuel_class=FuelClass.objects.get(fuel_class="Gasoline")) carbon_intensities = [] for period in range(2020, 2031): carbon_intensities.append( CarbonIntensityLimit( compliance_period=CompliancePeriod.objects.get( description=period), effective_date="{}-01-01".format(period), expiration_date="{}-12-31".format(period), density="85.28", fuel_class=FuelClass.objects.get(fuel_class="Diesel"))) carbon_intensities.append( CarbonIntensityLimit( compliance_period=CompliancePeriod.objects.get( description=period), effective_date="{}-01-01".format(period), expiration_date="{}-12-31".format(period), density="79.33", fuel_class=FuelClass.objects.get(fuel_class="Gasoline"))) CarbonIntensityLimit.objects.bulk_create(carbon_intensities) EnergyEffectivenessRatio.objects.create( category=EnergyEffectivenessRatioCategory.objects.get( name="Petroleum-based diesel fuel or renewable fuel in " "relation to diesel class fuel"), effective_date="2017-01-01", ratio="1.0", fuel_class=FuelClass.objects.get(fuel_class="Diesel")) EnergyEffectivenessRatio.objects.create( category=EnergyEffectivenessRatioCategory.objects.get( name="Petroleum-based gasoline, natural gas-based gasoline or " "renewable fuel in relation to gasoline class fuel"), effective_date="2017-01-01", ratio="1.0", fuel_class=FuelClass.objects.get(fuel_class="Gasoline")) EnergyEffectivenessRatio.objects.create( category=EnergyEffectivenessRatioCategory.objects.get( name="Hydrogen"), effective_date="2017-01-01", ratio="1.9", fuel_class=FuelClass.objects.get(fuel_class="Diesel")) EnergyEffectivenessRatio.objects.create( category=EnergyEffectivenessRatioCategory.objects.get( name="Hydrogen"), effective_date="2017-01-01", ratio="2.5", fuel_class=FuelClass.objects.get(fuel_class="Gasoline")) EnergyEffectivenessRatio.objects.create( category=EnergyEffectivenessRatioCategory.objects.get(name="LNG"), effective_date="2017-01-01", ratio="1.0", fuel_class=FuelClass.objects.get(fuel_class="Diesel")) EnergyEffectivenessRatio.objects.create( category=EnergyEffectivenessRatioCategory.objects.get(name="CNG"), effective_date="2017-01-01", ratio="0.9", fuel_class=FuelClass.objects.get(fuel_class="Diesel")) EnergyEffectivenessRatio.objects.create( category=EnergyEffectivenessRatioCategory.objects.get(name="CNG"), effective_date="2017-01-01", ratio="1.0", fuel_class=FuelClass.objects.get(fuel_class="Gasoline")) EnergyEffectivenessRatio.objects.create( category=EnergyEffectivenessRatioCategory.objects.get( name="Propane"), effective_date="2017-01-01", ratio="1.0", fuel_class=FuelClass.objects.get(fuel_class="Diesel")) EnergyEffectivenessRatio.objects.create( category=EnergyEffectivenessRatioCategory.objects.get( name="Propane"), effective_date="2017-01-01", ratio="1.0", fuel_class=FuelClass.objects.get(fuel_class="Gasoline")) EnergyEffectivenessRatio.objects.create( category=EnergyEffectivenessRatioCategory.objects.get( name="Electricity"), effective_date="2017-01-01", ratio="2.7", fuel_class=FuelClass.objects.get(fuel_class="Diesel")) EnergyEffectivenessRatio.objects.create( category=EnergyEffectivenessRatioCategory.objects.get( name="Electricity"), effective_date="2017-01-01", ratio="3.4", fuel_class=FuelClass.objects.get(fuel_class="Gasoline")) DefaultCarbonIntensity.objects.create( category=DefaultCarbonIntensityCategory.objects.get( name__iexact="Renewable Fuel in relation to diesel class fuel" ), effective_date="2017-01-01", density="98.96") DefaultCarbonIntensity.objects.create( category=DefaultCarbonIntensityCategory.objects.get( name__iexact="Propane"), effective_date="2017-01-01", density="75.35") DefaultCarbonIntensity.objects.create( category=DefaultCarbonIntensityCategory.objects.get( name__iexact="Renewable Fuel in relation to gasoline class fuel" ), effective_date="2017-01-01", density="88.14") DefaultCarbonIntensity.objects.create( category=DefaultCarbonIntensityCategory.objects.get( name__iexact="Natural gas-based gasoline"), effective_date="2017-01-01", density="90.07") DefaultCarbonIntensity.objects.create( category=DefaultCarbonIntensityCategory.objects.get( name__iexact="LNG"), effective_date="2017-01-01", density="112.65") DefaultCarbonIntensity.objects.create( category=DefaultCarbonIntensityCategory.objects.get( name__iexact="CNG"), effective_date="2017-01-01", density="63.64") DefaultCarbonIntensity.objects.create( category=DefaultCarbonIntensityCategory.objects.get( name__iexact="Electricity"), effective_date="2017-01-01", density="19.73") DefaultCarbonIntensity.objects.create( category=DefaultCarbonIntensityCategory.objects.get( name__iexact="Hydrogen"), effective_date="2017-01-01", density="96.82") EnergyDensity.objects.create( category=EnergyDensityCategory.objects.get( name="Petroleum-based diesel fuel or diesel fuel produced " "from biomass"), effective_date="2017-01-01", density="38.65") EnergyDensity.objects.create( category=EnergyDensityCategory.objects.get( name="Hydrogenation-derived renewable diesel fuel"), effective_date="2017-01-01", density="36.51") EnergyDensity.objects.create( category=EnergyDensityCategory.objects.get(name="Biodiesel"), effective_date="2017-01-01", density="35.40") EnergyDensity.objects.create( category=EnergyDensityCategory.objects.get( name="Petroleum-based gasoline, natural gas-based " "gasoline or gasoline produced from biomass"), effective_date="2017-01-01", density="34.69") EnergyDensity.objects.create( category=EnergyDensityCategory.objects.get(name="Ethanol"), effective_date="2017-01-01", density="23.58") EnergyDensity.objects.create( category=EnergyDensityCategory.objects.get(name="Hydrogen"), effective_date="2017-01-01", density="141.24") EnergyDensity.objects.create( category=EnergyDensityCategory.objects.get(name="LNG"), effective_date="2017-01-01", density="52.46") EnergyDensity.objects.create( category=EnergyDensityCategory.objects.get(name="CNG"), effective_date="2017-01-01", density="37.85") EnergyDensity.objects.create( category=EnergyDensityCategory.objects.get(name="Propane"), effective_date="2017-01-01", density="25.47") EnergyDensity.objects.create( category=EnergyDensityCategory.objects.get(name="Electricity"), effective_date="2017-01-01", density="3.60") CarbonIntensityLimit.objects.update(effective_date="2017-01-01", expiration_date=None) PetroleumCarbonIntensity.objects.create( category=PetroleumCarbonIntensityCategory.objects.get( name="Petroleum-based diesel"), effective_date="2017-01-01", density="94.76") PetroleumCarbonIntensity.objects.create( category=PetroleumCarbonIntensityCategory.objects.get( name="Petroleum-based gasoline"), effective_date="2017-01-01", density="88.14") ExpectedUse.objects.create(description="Other", display_order="99", effective_date="2017-01-01") ExpectedUse.objects.create(description="Heating Oil", display_order="1", effective_date="2017-01-01") ExpectedUse.objects.create( description="Department of National Defence (Canada)", display_order="2", effective_date="2017-01-01") ExpectedUse.objects.create(description="Aviation", display_order="3", effective_date="2017-01-01") NotionalTransferType.objects.create(the_type="Received", display_order="1", effective_date="2017-01-01") NotionalTransferType.objects.create(the_type="Transferred", display_order="2", effective_date="2017-01-01") prescribed_carbon_intensity = \ CarbonIntensityDeterminationType.objects.create( display_order="1", effective_date="2017-01-01", the_type="Carbon Intensity" ) provision = ProvisionOfTheAct.objects.create( description="Prescribed carbon intensity", display_order="1", effective_date="2017-01-01", expiration_date=None, provision="Section 6 (5) (a)") ApprovedFuelProvision.objects.create( fuel=ApprovedFuel.objects.get(name="Petroleum-based gasoline"), provision_act=provision, determination_type=prescribed_carbon_intensity) provision = ProvisionOfTheAct.objects.create( description="Prescribed carbon intensity", display_order="2", effective_date="2017-01-01", expiration_date=None, provision="Section 6 (5) (b)") ApprovedFuelProvision.objects.create( fuel=ApprovedFuel.objects.get(name="Petroleum-based diesel"), provision_act=provision, determination_type=prescribed_carbon_intensity) # other fuel types approved_fuel_code = \ CarbonIntensityDeterminationType.objects.create( display_order="2", effective_date="2017-01-01", the_type="Fuel Code" ) fuel_types = ApprovedFuel.objects.exclude( name__in=["Petroleum-based diesel", "Petroleum-based gasoline"]) # Section 6 (5) (c) provision = ProvisionOfTheAct.objects.create( description="Approved fuel code", display_order="3", effective_date="2017-01-01", expiration_date=None, provision="Section 6 (5) (c)") obj = [ ApprovedFuelProvision(fuel=fuel_type, provision_act=provision, determination_type=approved_fuel_code) for fuel_type in fuel_types ] ApprovedFuelProvision.objects.bulk_create(obj) # Section 6 (5) (d) (i) default_carbon_intensity = \ CarbonIntensityDeterminationType.objects.create( display_order="3", effective_date="2017-01-01", the_type="Default Carbon Intensity" ) provision = ProvisionOfTheAct.objects.create( description="Default Carbon Intensity Value", display_order="4", effective_date="2017-01-01", expiration_date=None, provision="Section 6 (5) (d) (i)") obj = [ ApprovedFuelProvision(fuel=fuel_type, provision_act=provision, determination_type=default_carbon_intensity) for fuel_type in fuel_types ] ApprovedFuelProvision.objects.bulk_create(obj) # Section 6 (5) (d) (ii) (A) gh_genius = \ CarbonIntensityDeterminationType.objects.create( display_order="4", effective_date="2017-01-01", the_type="GHGenius" ) provision = ProvisionOfTheAct.objects.create( description="GHGenius modelled", display_order="5", effective_date="2017-01-01", expiration_date=None, provision="Section 6 (5) (d) (ii) (A)") obj = [ ApprovedFuelProvision(fuel=fuel_type, provision_act=provision, determination_type=gh_genius) for fuel_type in fuel_types ] ApprovedFuelProvision.objects.bulk_create(obj) # Section 6 (5) (d) (ii) (B) alternative_method = \ CarbonIntensityDeterminationType.objects.create( display_order="5", effective_date="2017-01-01", the_type="Alternative" ) provision = ProvisionOfTheAct.objects.create( description="Alternative Method", display_order="6", effective_date="2017-01-01", expiration_date=None, provision="Section 6 (5) (d) (ii) (B)") obj = [ ApprovedFuelProvision(fuel=fuel_type, provision_act=provision, determination_type=alternative_method) for fuel_type in fuel_types ] ApprovedFuelProvision.objects.bulk_create(obj) TransactionType.objects.create(the_type="Purchased", display_order="1", effective_date="2017-01-01") TransactionType.objects.create(the_type="Sold", display_order="2", effective_date="2017-01-01")