Skip to content

Commit c45a3e3

Browse files
authored
Merge pull request #4233 from bcgov/chore/966-update-product-name-and-pwaei
chore: 966 renaming product and adding pwaei
2 parents bb5a339 + 5caa9d8 commit c45a3e3

7 files changed

Lines changed: 53 additions & 28 deletions

File tree

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
# Generated by Django 5.1.15 on 2026-02-03 21:41
22

3+
from decimal import Decimal
34
from django.db import migrations
45

56

6-
def add_product(apps, schema_monitor):
7+
def add_product_and_pwaei(apps, schema_monitor):
78
'''
89
Add the new Pulp & Paper: Lime Revovery Kiln
910
'''
1011
RegulatedProduct = apps.get_model('registration', 'RegulatedProduct')
12+
ProductEmissionIntensity = apps.get_model('reporting', 'ProductEmissionIntensity')
13+
1114
RegulatedProduct.objects.create(
12-
name="Pulp and paper: lime recovery kiln",
15+
name="Pulp and paper: lime recovered by kiln",
1316
unit="Tonnes dry recovered lime (calcium oxide)",
1417
is_regulated=True,
1518
)
19+
ProductEmissionIntensity.objects.create(
20+
product_id=RegulatedProduct.objects.get(name="Pulp and paper: lime recovered by kiln").id,
21+
product_weighted_average_emission_intensity=Decimal("0.3822"),
22+
valid_from='2023-01-01',
23+
valid_to='9999-12-31',
24+
)
1625

1726

18-
def reverse_add_product(apps, schema_monitor):
27+
def reverse_add_product_and_pwaei(apps, schema_monitor):
1928
RegulatedProduct = apps.get_model('registration', 'RegulatedProduct')
20-
RegulatedProduct.objects.filter(name="Pulp and paper: lime recovery kiln").delete()
29+
ProductEmissionIntensity = apps.get_model('reporting', 'ProductEmissionIntensity')
30+
31+
ProductEmissionIntensity.objects.filter(product__name="Pulp and paper: lime recovered by kiln").delete()
32+
RegulatedProduct.objects.filter(name="Pulp and paper: lime recovered by kiln").delete()
2133

2234

2335
class Migration(migrations.Migration):
@@ -27,5 +39,5 @@ class Migration(migrations.Migration):
2739
]
2840

2941
operations = [
30-
migrations.RunPython(add_product, reverse_add_product),
42+
migrations.RunPython(add_product_and_pwaei, reverse_add_product_and_pwaei),
3143
]

bc_obps/registration/tests/models/test_initial_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_regulated_product_initial_data(self):
144144
'Processing sour gas - oil equivalent',
145145
'Processing sweet gas - oil equivalent',
146146
'Pulp and paper: chemical pulp',
147-
'Pulp and paper: lime recovery kiln',
147+
'Pulp and paper: lime recovered by kiln',
148148
'Pulp and paper: non-chemical pulp',
149149
'Pulp and paper: paper (except newsprint and tissue paper)',
150150
'Pulp and paper: tissue Paper',

bc_obps/reporting/tests/models/test_product_emission_intensity.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
from common.tests.utils.helpers import BaseTestCase
2+
from django.db.models import Count
23
from reporting.models import ProductEmissionIntensity
34
from registration.models import RegulatedProduct
45
from django.test import TestCase
56

67

78
class TestInitialData(TestCase):
8-
def test_all_products_have_emission_intensity(self):
9-
product_list = RegulatedProduct.objects.all().values_list('id', flat=True)
10-
missing_records = ProductEmissionIntensity.objects.all().exclude(id__in=product_list).count()
11-
12-
self.assertEqual(missing_records, 0)
9+
def test_all_regulated_products_have_emission_intensity(self):
10+
"""
11+
Assert that every regulated product has at least one ProductEmissionIntensity record defined
12+
"""
13+
assert (
14+
not RegulatedProduct.objects.prefetch_related("productemissionintensity")
15+
.filter(is_regulated=True)
16+
.annotate(emission_intensity_count=Count("productemissionintensity"))
17+
.filter(emission_intensity_count=0)
18+
.exists()
19+
)
1320

1421

1522
class EmissionCategoryModelTest(BaseTestCase):

bciers/apps/reporting/src/app/components/facility/FacilityEmissionAllocationForm.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,29 @@ const validateFormData = (
131131
industrialEmissionAllocations?.products?.find(
132132
(p) => p.product_name === "Pulp and paper: chemical pulp",
133133
);
134+
const limeRecoveredByKilnAllocation =
135+
industrialEmissionAllocations?.products?.find(
136+
(p) => p.product_name === "Pulp and paper: lime recovered by kiln",
137+
);
134138
if (!chemicalPulpAllocation)
135139
newErrors.push(
136140
"Missing Product: 'Pulp and paper: chemical pulp'. Please add the product on the operation review page",
137141
);
142+
else if (!limeRecoveredByKilnAllocation)
143+
newErrors.push(
144+
"Missing Product: 'Pulp and paper: lime recovered by kiln'. Please add the product on the operation review page",
145+
);
138146
else if (
139-
chemicalPulpAllocation.allocated_quantity -
147+
// overlapping industrial process emissions are necessarily allocated to either of these products,
148+
// we can give the user an early warning if they didn't allocate enough at this stage
149+
chemicalPulpAllocation.allocated_quantity +
150+
limeRecoveredByKilnAllocation.allocated_quantity -
140151
overlappingIndustrialProcessEmissions <
141152
0
142153
)
143154
newErrors.push(
144-
"Invalid allocation: Industrial Process quantity allocated to product 'Pulp and paper: chemical pulp' is too low",
155+
`Invalid allocation: Industrial Process quantity allocated betwen 'Pulp and paper:
156+
chemical pulp' and 'Pulp and paper: lime recovered by kiln' is too low`,
145157
);
146158
}
147159

bciers/apps/reporting/src/app/components/operations/OperationReviewForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export default function OperationReviewForm({
162162
};
163163

164164
// Regulated product IDs 16 and 43 are the Pulp and paper: chemical pulp
165-
// and Pulp and paper: lime recovery kiln, respectively
165+
// and Pulp and paper: lime recovered by kiln, respectively
166166
const selectedProductIds: number[] = formDataState.regulated_products;
167167
const displayPulpAndPaperHelpText =
168168
(selectedProductIds.includes(16) && !selectedProductIds.includes(43)) ||
@@ -207,7 +207,7 @@ export default function OperationReviewForm({
207207
regulated_products: {
208208
...uiSchema.regulated_products,
209209
"ui:help": `If this is a chemical pulp mill that recovered lime by kiln,
210-
select both 'Pulp and paper: chemical pulp' and 'Pulp and paper: lime recovery kiln'`,
210+
select both 'Pulp and paper: chemical pulp' and 'Pulp and paper: lime recovered by kiln'`,
211211
},
212212
}),
213213
}}

bciers/apps/reporting/src/tests/components/operations/OperationReviewForm.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,14 @@ describe("OperationReviewForm Component", () => {
465465
).toBeInTheDocument();
466466
});
467467

468-
it("displays a help text when either chemical pulp / lime recovery kiln are selected, but not both", async () => {
468+
it("displays a help text when either chemical pulp / lime recovered by kiln are selected, but not both", async () => {
469469
async function renderWithProductIds(productIds: number[]) {
470470
const allRegulatedProducts = [
471471
{ id: 1, name: "Product 1", unit: "BCRCT", is_regulated: true },
472472
{ id: 16, name: "chemical pulp", unit: "BCRCT", is_regulated: true },
473473
{
474474
id: 43,
475-
name: "lime recovery kiln",
475+
name: "lime recovered by kiln",
476476
is_regulated: true,
477477
},
478478
];

bciers/libs/components/src/form/fields/FieldHelpTemplate.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
"use client";
22

3-
import { BC_GOV_BACKGROUND_COLOR_BLUE } from "@bciers/styles/colors";
4-
import { Typography } from "@mui/material";
53
import { FieldHelpProps } from "@rjsf/utils";
64

75
function FieldHelpTemplate(props: FieldHelpProps) {
86
const { help } = props;
97
return (
10-
<span>
11-
<Typography
12-
variant="body2"
13-
color={BC_GOV_BACKGROUND_COLOR_BLUE}
14-
fontStyle="italic"
15-
fontSize={16}
16-
>
8+
help && (
9+
<small>
10+
<b>Note: </b>
1711
{help}
18-
</Typography>
19-
</span>
12+
</small>
13+
)
2014
);
2115
}
2216

0 commit comments

Comments
 (0)