From 1003ef9820b363fb1faf446477dd90ddb9f29bc6 Mon Sep 17 00:00:00 2001 From: Ross Perry Date: Fri, 19 Jan 2024 19:16:49 -0700 Subject: [PATCH] Apply GHG and GHGI unit versions to canonical columns (#4462) * eeej small files * add ghg intensity options to org model * add ghg intensity to org settings * org migration for ghg display units * precommit * update tests --------- Co-authored-by: Katherine Fleming <2205659+kflemin@users.noreply.github.com> --- .../migrations/0029_auto_20240105_1257.py | 23 ++++++++++++++ seed/lib/superperms/orgs/models.py | 4 +++ .../organization_settings_controller.js | 30 +++++++++++++++++++ .../seed/partials/organization_settings.html | 28 +++++++++++++++++ seed/tests/test_account_views.py | 6 ++++ seed/views/v3/organizations.py | 14 +++++++++ 6 files changed, 105 insertions(+) create mode 100644 seed/lib/superperms/orgs/migrations/0029_auto_20240105_1257.py diff --git a/seed/lib/superperms/orgs/migrations/0029_auto_20240105_1257.py b/seed/lib/superperms/orgs/migrations/0029_auto_20240105_1257.py new file mode 100644 index 0000000000..cbf67fbbcb --- /dev/null +++ b/seed/lib/superperms/orgs/migrations/0029_auto_20240105_1257.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.23 on 2024-01-05 20:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('orgs', '0028_organization_audit_template_report_type'), + ] + + operations = [ + migrations.AlterField( + model_name='organization', + name='display_units_ghg', + field=models.CharField(choices=[('kgCO2e/year', 'kgCO2e/year'), ('MtCO2e/year', 'MtCO2e/year')], default='MtCO2e/year', max_length=32), + ), + migrations.AlterField( + model_name='organization', + name='display_units_ghg_intensity', + field=models.CharField(choices=[('kgCO2e/ft**2/year', 'kgCO2e/ft²/year'), ('MtCO2e/ft**2/year', 'MtCO2e/ft²/year'), ('kgCO2e/m**2/year', 'kgCO2e/m²/year'), ('MtCO2e/m**2/year', 'MtCO2e/m²/year')], default='kgCO2e/ft**2/year', max_length=32), + ), + ] diff --git a/seed/lib/superperms/orgs/models.py b/seed/lib/superperms/orgs/models.py index 0c0daf35f1..f42d5503a4 100644 --- a/seed/lib/superperms/orgs/models.py +++ b/seed/lib/superperms/orgs/models.py @@ -107,11 +107,15 @@ class Organization(models.Model): ) MEASUREMENT_CHOICES_GHG = ( + ('kgCO2e/year', 'kgCO2e/year'), ('MtCO2e/year', 'MtCO2e/year'), ) MEASUREMENT_CHOICES_GHG_INTENSITY = ( ('kgCO2e/ft**2/year', 'kgCO2e/ft²/year'), + ('MtCO2e/ft**2/year', 'MtCO2e/ft²/year'), + ('kgCO2e/m**2/year', 'kgCO2e/m²/year'), + ('MtCO2e/m**2/year', 'MtCO2e/m²/year'), ) US = 1 diff --git a/seed/static/seed/js/controllers/organization_settings_controller.js b/seed/static/seed/js/controllers/organization_settings_controller.js index 8dc3af7ee3..668a61496d 100644 --- a/seed/static/seed/js/controllers/organization_settings_controller.js +++ b/seed/static/seed/js/controllers/organization_settings_controller.js @@ -89,6 +89,36 @@ angular.module('BE.seed.controller.organization_settings', []).controller('organ } ]; + $scope.unit_options_ghg = [ + { + label: $translate.instant('kgCO2e/year'), + value: 'kgCO2e/year' + }, + { + label: $translate.instant('MtCO2e/year'), + value: 'MtCO2e/year' + }, + ] + + $scope.unit_options_ghg_intensity = [ + { + label: $translate.instant('kgCO2e/ft²/year'), + value: 'kgCO2e/ft**2/year' + }, + { + label: $translate.instant('kgCO2e/m²/year'), + value: 'kgCO2e/m**2/year' + }, + { + label: $translate.instant('MtCO2e/ft²/year'), + value: 'MtCO2e/ft**2/year' + }, + { + label: $translate.instant('MtCO2e/m²/year'), + value: 'MtCO2e/m**2/year' + }, + ] + // Ideally, these units and types for meters should be translatable. $scope.chosen_type_unit = { type: null, diff --git a/seed/static/seed/partials/organization_settings.html b/seed/static/seed/partials/organization_settings.html index dc8973c4a9..0071d32f39 100644 --- a/seed/static/seed/partials/organization_settings.html +++ b/seed/static/seed/partials/organization_settings.html @@ -938,6 +938,34 @@

Measurement unit display for energy use intensities (EUI)

+
+
+

Measurement unit display for Green House Gas Emissions (GHG)

+
+
+
+ +
+
+
+
+
+ +
+
+

Measurement unit display for Green House Gas Emission Intensity (GHGI)

+
+
+
+ +
+
+
+
+
+

METER_DISPLAY_SETTINGS_TITLE

diff --git a/seed/tests/test_account_views.py b/seed/tests/test_account_views.py index a5d3069018..2754f8a9be 100644 --- a/seed/tests/test_account_views.py +++ b/seed/tests/test_account_views.py @@ -74,6 +74,8 @@ def test_dict_org(self): 'parent_id': self.org.pk, 'display_units_eui': 'kBtu/ft**2/year', 'display_units_area': 'ft**2', + 'display_units_ghg': 'MtCO2e/year', + 'display_units_ghg_intensity': 'kgCO2e/ft**2/year', 'display_decimal_places': 2, 'cycles': [{ 'name': self.cal_year_name, @@ -179,6 +181,8 @@ def test_dict_org_w_member_in_parent_and_child(self): 'parent_id': self.org.pk, 'display_units_eui': 'kBtu/ft**2/year', 'display_units_area': 'ft**2', + 'display_units_ghg': 'MtCO2e/year', + 'display_units_ghg_intensity': 'kgCO2e/ft**2/year', 'display_decimal_places': 2, 'cycles': [{ 'name': self.cal_year_name, @@ -211,6 +215,8 @@ def test_dict_org_w_member_in_parent_and_child(self): 'parent_id': self.org.pk, 'display_units_eui': 'kBtu/ft**2/year', 'display_units_area': 'ft**2', + 'display_units_ghg': 'MtCO2e/year', + 'display_units_ghg_intensity': 'kgCO2e/ft**2/year', 'display_decimal_places': 2, 'cycles': [{ 'name': self.cal_year_name, diff --git a/seed/views/v3/organizations.py b/seed/views/v3/organizations.py index 6017b99f52..257cf9ed70 100644 --- a/seed/views/v3/organizations.py +++ b/seed/views/v3/organizations.py @@ -126,6 +126,8 @@ def _dict_org(request, organizations): 'is_parent': o.is_parent, 'parent_id': o.parent_id, 'display_units_eui': o.display_units_eui, + 'display_units_ghg': o.display_units_ghg, + 'display_units_ghg_intensity': o.display_units_ghg_intensity, 'display_units_area': o.display_units_area, 'display_decimal_places': o.display_decimal_places, 'cycles': cycles, @@ -500,6 +502,18 @@ def warn_bad_units(kind, unit_string): else: warn_bad_pint_spec('eui', desired_display_units_eui) + desired_display_units_ghg = posted_org.get('display_units_ghg') + if is_valid_choice(Organization.MEASUREMENT_CHOICES_GHG, desired_display_units_ghg): + org.display_units_ghg = desired_display_units_ghg + else: + warn_bad_pint_spec('ghg', desired_display_units_ghg) + + desired_display_units_ghg_intensity = posted_org.get('display_units_ghg_intensity') + if is_valid_choice(Organization.MEASUREMENT_CHOICES_GHG_INTENSITY, desired_display_units_ghg_intensity): + org.display_units_ghg_intensity = desired_display_units_ghg_intensity + else: + warn_bad_pint_spec('ghg_intensity', desired_display_units_ghg_intensity) + desired_display_units_area = posted_org.get('display_units_area') if is_valid_choice(Organization.MEASUREMENT_CHOICES_AREA, desired_display_units_area): org.display_units_area = desired_display_units_area