Skip to content

Commit

Permalink
Merge pull request #1915 from bcgov/chore/243-add-report-version-model
Browse files Browse the repository at this point in the history
243 ReportVersion model
  • Loading branch information
pbastia authored Jul 5, 2024
2 parents 2a32936 + 222155e commit ecbec8e
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 97 deletions.
1 change: 1 addition & 0 deletions bc_obps/registration/tests/models/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def setUpTestData(cls):
("user_operators", "user operator", None, 2),
("parent_operators", "parent operator", None, None),
("operation_ownerships", "operation ownership timeline", None, None),
("report", "report", None, None),
]

def test_check_cra_business_number_format(self):
Expand Down
132 changes: 92 additions & 40 deletions bc_obps/reporting/migrations/0006_reinit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.6 on 2024-07-02 21:15
# Generated by Django 5.0.6 on 2024-07-05 21:09

import django.contrib.postgres.constraints
import django.contrib.postgres.fields.ranges
Expand All @@ -10,7 +10,7 @@
class Migration(migrations.Migration):

dependencies = [
('registration', '0021_V1_6_0'),
('registration', '0022_remove_historicalwellauthorizationnumber_facility_and_more'),
('reporting', '0005_delete_sourcetype'),
]

Expand Down Expand Up @@ -52,47 +52,43 @@ class Migration(migrations.Migration):
},
),
migrations.CreateModel(
name='GasType',
name='FuelType',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(db_comment='The name of a fuel type (example: Crude Oil)', max_length=1000)),
(
'name',
models.CharField(
db_comment='The name of a greenhouse gas type (example: Carbon Dioxide)', max_length=1000
),
),
(
'chemical_formula',
'unit',
models.CharField(
db_comment='The chemical formula representation of a greenhouse gast type (example: CO2)',
max_length=100,
db_comment='The unit of measurement for this fuel type (example: kilolitres)', max_length=1000
),
),
],
options={
'db_table': 'erc"."gas_type',
'db_table_comment': 'This table contains the list of gas types that can be reported as defined in GGERR (Greenhous Gas Emission Reporting Regulation)',
'db_table': 'erc"."fuel_type',
'db_table_comment': 'This table contains the list of fuel types that can be reported.',
},
),
migrations.CreateModel(
name='FuelType',
name='GasType',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
(
'name',
models.CharField(db_comment='The name of a fuel type (example: Crude Oil)', max_length=1000),
models.CharField(
db_comment='The name of a greenhouse gas type (example: Carbon Dioxide)', max_length=1000
),
),
(
'unit',
'chemical_formula',
models.CharField(
db_comment='The unit of measurement for this fuel type (example: kilolitres)',
max_length=1000,
db_comment='The chemical formula representation of a greenhouse gast type (example: CO2)',
max_length=100,
),
),
],
options={
'db_table': 'erc"."fuel_type',
'db_table_comment': 'This table contains the list of fuel types that can be reported.',
'db_table': 'erc"."gas_type',
'db_table_comment': 'This table contains the list of gas types that can be reported as defined in GGERR (Greenhous Gas Emission Reporting Regulation)',
},
),
migrations.CreateModel(
Expand Down Expand Up @@ -150,6 +146,29 @@ class Migration(migrations.Migration):
'db_table_comment': 'Reporting year',
},
),
migrations.CreateModel(
name='ReportVersion',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
(
'is_latest_submitted',
models.BooleanField(db_comment='True if this version is the latest submitted one', default=False),
),
(
'status',
models.CharField(
choices=[('draft', 'Draft'), ('submitted', 'Submitted')],
db_comment='The status for this report version: draft or submitted.',
default='draft',
max_length=1000,
),
),
],
options={
'db_table': 'erc"."report_version',
'db_table_comment': 'A table representing the multiple versions that a single report can have.',
},
),
migrations.CreateModel(
name='SourceType',
fields=[
Expand All @@ -161,6 +180,10 @@ class Migration(migrations.Migration):
'db_table_comment': 'Source types',
},
),
migrations.AlterModelTableComment(
name='report',
table_comment='A table to store report instances. Each operation has at most one report per year.',
),
migrations.RemoveField(
model_name='report',
name='created_at',
Expand All @@ -173,6 +196,10 @@ class Migration(migrations.Migration):
model_name='report',
name='title',
),
migrations.RemoveField(
model_name='reportfacility',
name='report',
),
migrations.RemoveField(
model_name='reportoperation',
name='report',
Expand All @@ -181,20 +208,21 @@ class Migration(migrations.Migration):
model_name='report',
name='operation',
field=models.ForeignKey(
db_comment='The operation to which this report belongs',
null=True,
db_comment='The operation for which this report was filed',
default='00000000-0000-0000-0000-000000000000',
on_delete=django.db.models.deletion.DO_NOTHING,
to='registration.operation',
),
preserve_default=False,
),
migrations.AddField(
model_name='report',
name='report_operation',
field=models.OneToOneField(
db_comment='The report this operation information relates to',
default=1,
on_delete=django.db.models.deletion.CASCADE,
to='reporting.reportoperation',
name='operator',
field=models.ForeignKey(
db_comment='The operator to which this report belongs',
default='00000000-0000-0000-0000-000000000000',
on_delete=django.db.models.deletion.DO_NOTHING,
to='registration.operator',
),
preserve_default=False,
),
Expand All @@ -205,16 +233,6 @@ class Migration(migrations.Migration):
blank=True, db_comment='The BC GHG ID of the facility as reported', max_length=1000, null=True
),
),
migrations.AlterField(
model_name='reportfacility',
name='report',
field=models.ForeignKey(
db_comment='The report this facility information is related to',
on_delete=django.db.models.deletion.CASCADE,
related_name='report_facilities',
to='reporting.report',
),
),
migrations.AlterField(
model_name='reportoperation',
name='bc_obps_regulated_operation_id',
Expand Down Expand Up @@ -397,12 +415,46 @@ class Migration(migrations.Migration):
name='reporting_year',
field=models.ForeignKey(
db_comment='The reporting year, for which this report is filled',
default=1900,
default=9999,
on_delete=django.db.models.deletion.DO_NOTHING,
to='reporting.reportingyear',
),
preserve_default=False,
),
migrations.AddField(
model_name='reportversion',
name='report',
field=models.ForeignKey(
db_comment='The report to which this version applied.',
on_delete=django.db.models.deletion.CASCADE,
related_name='report_versions',
to='reporting.report',
),
),
migrations.AddField(
model_name='reportfacility',
name='report_version',
field=models.ForeignKey(
db_comment='The report this facility information is related to',
default=0,
on_delete=django.db.models.deletion.CASCADE,
related_name='report_facilities',
to='reporting.reportversion',
),
preserve_default=False,
),
migrations.AddField(
model_name='reportoperation',
name='report_version',
field=models.OneToOneField(
db_comment='The report this operation information relates to',
default=0,
on_delete=django.db.models.deletion.CASCADE,
related_name='report_operation',
to='reporting.reportversion',
),
preserve_default=False,
),
migrations.AddField(
model_name='configurationelement',
name='source_type',
Expand Down
3 changes: 3 additions & 0 deletions bc_obps/reporting/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from .report import Report
from .report_version import ReportVersion
from .source_type import SourceType
from .report_operation import ReportOperation
from .report_facility import ReportFacility
from .reporting_year import ReportingYear


from .gas_type import GasType
from .fuel_type import FuelType
from .methodology import Methodology
Expand All @@ -16,6 +18,7 @@

__all__ = [
"Report",
"ReportVersion",
"SourceType",
"ReportOperation",
"ReportFacility",
Expand Down
20 changes: 9 additions & 11 deletions bc_obps/reporting/models/report.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models
from common.models.base_model import BaseModel
from registration.models.operation import Operation
from reporting.models.report_operation import ReportOperation
from registration.models.operator import Operator
from reporting.models.reporting_year import ReportingYear


Expand All @@ -10,9 +10,14 @@ class Report(BaseModel):
Report model for storing OBPS reports
"""

# This will need to be updated
# This is needed in case the operation changes hands and doesn't belong to the operator.
# The report still belongs to the operator which filed it.
operator = models.ForeignKey(
Operator, on_delete=models.DO_NOTHING, db_comment="The operator to which this report belongs"
)

operation = models.ForeignKey(
Operation, on_delete=models.DO_NOTHING, db_comment="The operation to which this report belongs", null=True
Operation, on_delete=models.DO_NOTHING, db_comment="The operation for which this report was filed"
)

reporting_year = models.ForeignKey(
Expand All @@ -23,14 +28,7 @@ class Report(BaseModel):
db_comment="The reporting year, for which this report is filled",
)

# A report can only be for one single operation
report_operation = models.OneToOneField(
ReportOperation,
on_delete=models.CASCADE,
db_comment="The report this operation information relates to",
)

class Meta:
db_table_comment = "A table to store reports"
db_table_comment = "A table to store report instances. Each operation has at most one report per year."
db_table = 'erc"."report'
app_label = 'reporting'
6 changes: 3 additions & 3 deletions bc_obps/reporting/models/report_facility.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from common.models import BaseModel
from django.db import models
from registration.models import ReportingActivity, RegulatedProduct
from reporting.models import Report
from reporting.models import ReportVersion


class ReportFacility(BaseModel):

report = models.ForeignKey(
Report,
report_version = models.ForeignKey(
ReportVersion,
on_delete=models.CASCADE,
db_comment="The report this facility information is related to",
related_name="report_facilities",
Expand Down
18 changes: 16 additions & 2 deletions bc_obps/reporting/models/report_operation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
from common.models import BaseModel
from django.db import models
from registration.models import ReportingActivity
from reporting.models.report_version import ReportVersion


class ReportOperation(BaseModel):
"""
Report model to store operation information
"""

# A report version can only have one single record of operation information
report_version = models.OneToOneField(
ReportVersion,
on_delete=models.CASCADE,
related_name="report_operation",
db_comment="The report this operation information relates to",
)

class OperationType(models.TextChoices):
SFO = "sfo"
LFO = "lfo"
Expand All @@ -18,9 +27,14 @@ class OperationType(models.TextChoices):
operator_trade_name = models.CharField(
max_length=1000, db_comment="The trade name of the operator operating this operation", blank=True, null=True
)
operation_name = models.CharField(max_length=1000, db_comment="The name of the operation, for which this report is")
operation_name = models.CharField(
max_length=1000,
db_comment="The name of the operation, for which this report is",
)
operation_type = models.CharField(
max_length=1000, choices=OperationType.choices, db_comment="The type of the operation, LFO or SFO"
max_length=1000,
choices=OperationType.choices,
db_comment="The type of the operation, LFO or SFO",
)
operation_bcghgid = models.CharField(
max_length=1000, db_comment="The BCGHGH ID of the operation", blank=True, null=True
Expand Down
33 changes: 33 additions & 0 deletions bc_obps/reporting/models/report_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.db import models
from common.models.base_model import BaseModel
from reporting.models.report import Report


class ReportVersion(BaseModel):

report = models.ForeignKey(
Report,
on_delete=models.CASCADE,
db_comment="The report to which this version applied.",
related_name="report_versions",
)
is_latest_submitted = models.BooleanField(
db_comment="True if this version is the latest submitted one",
default=False,
)

class ReportVersionStatus(models.TextChoices):
Draft = 'draft'
Submitted = 'submitted'

status = models.CharField(
max_length=1000,
choices=ReportVersionStatus.choices,
db_comment="The status for this report version: draft or submitted.",
default=ReportVersionStatus.Draft,
)

class Meta:
db_table_comment = "A table representing the multiple versions that a single report can have."
db_table = 'erc"."report_version'
app_label = 'reporting'
Loading

0 comments on commit ecbec8e

Please sign in to comment.