Skip to content

Commit 500ba79

Browse files
committed
Make configurable
1 parent e5464b5 commit 500ba79

File tree

6 files changed

+109
-5
lines changed

6 files changed

+109
-5
lines changed

seed/audit_template/audit_template.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ def build_xml(self, state, report_type, display_field):
276276
return None, messages
277277

278278
view = state.propertyview_set.first()
279+
org = view.property.organization
279280

280281
gfa = state.gross_floor_area
281282
if isinstance(gfa, int):
@@ -335,15 +336,15 @@ def build_xml(self, state, report_type, display_field):
335336
),
336337
)
337338
),
338-
*_build_measures_element(em, view.property),
339+
*([] if not org.audit_template_export_measures else _build_measures_element(em, view.property)),
339340
em.Reports(
340341
em.Report(
341342
em.Scenarios(
342343
{},
343344
em.Scenario(
344345
{"ID": "ScenarioType-69817879941680"},
345-
*_build_resource_uses(em, view.property),
346-
*build_time_series_data(em, view.property),
346+
*([] if not org.audit_template_export_meters else _build_resource_uses(em, view.property)),
347+
*([] if not org.audit_template_export_meters else build_time_series_data(em, view.property)),
347348
),
348349
),
349350
{"ID": "ReportType-69909846999993"},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 3.2.25 on 2025-02-03 21:32
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("orgs", "0039_alter_organization_ubid_threshold"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="organization",
14+
name="audit_template_export_measures",
15+
field=models.BooleanField(default=True),
16+
),
17+
migrations.AddField(
18+
model_name="organization",
19+
name="audit_template_export_meters",
20+
field=models.BooleanField(default=True),
21+
),
22+
]

seed/lib/superperms/orgs/models.py

+2
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ class Meta:
300300
audit_template_city_id = models.IntegerField(blank=True, null=True)
301301
audit_template_conditional_import = models.BooleanField(default=True)
302302
audit_template_sync_enabled = models.BooleanField(default=False)
303+
audit_template_export_meters = models.BooleanField(default=True)
304+
audit_template_export_measures = models.BooleanField(default=True)
303305

304306
# Salesforce Functionality
305307
salesforce_enabled = models.BooleanField(default=False)

seed/static/seed/partials/organization_settings.html

+22
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,28 @@ <h3 translate>Audit Template Submission Status</h3>
251251
</div>
252252
</div>
253253

254+
<div class="section_content_container">
255+
<div class="section_content with_padding">
256+
<h3 translate>Audit Template Fields</h3>
257+
<form class="form-horizontal" role="form">
258+
<div class="form-group">
259+
<div class="col-sm-5">
260+
<div class="multi-select-container">
261+
<div class="col-sm-5">
262+
<input type="checkbox" class="form-control" style="width: 34px" ng-model="org.audit_template_export_meters" ng-disabled="::!auth.requires_owner" />
263+
<h3 translate style="padding-left: 5px; align-content: center;">meters</h3>
264+
</div>
265+
<div class="col-sm-5">
266+
<input type="checkbox" class="form-control" style="width: 34px" ng-model="org.audit_template_export_measures" ng-disabled="::!auth.requires_owner" />
267+
<h3 translate style="padding-left: 5px; align-content: center;">measures</h3>
268+
</div>
269+
</div>
270+
</div>
271+
</div>
272+
</form>
273+
</div>
274+
</div>
275+
254276
<div class="section_content_container">
255277
<div class="section_content with_padding">
256278
<h3 translate>Conditional Import</h3>

seed/tests/test_audit_template.py

+49-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# from seed.audit_template.audit_template import build_xml
1818
from seed.audit_template.audit_template import AuditTemplate
1919
from seed.landing.models import SEEDUser as User
20+
from seed.lib.tkbl.tkbl import SCOPE_ONE_EMISSION_CODES
2021
from seed.models import Meter, MeterReading, Uniformat
2122
from seed.test_helpers.fake import (
2223
FakeCycleFactory,
@@ -240,8 +241,6 @@ def test_build_xml_from_property_with_meter_readings(self):
240241
self.assertEqual(float(reading.text), 123)
241242

242243
def test_build_xml_from_property_with_measures(self):
243-
from seed.lib.tkbl.tkbl import SCOPE_ONE_EMISSION_CODES
244-
245244
# Set Up
246245
self.element1 = self.element_factory.get_element(
247246
property=self.view1.property, code=Uniformat.objects.filter(code__in=SCOPE_ONE_EMISSION_CODES)[1]
@@ -285,6 +284,54 @@ def test_build_xml_from_property_with_measures(self):
285284
{m.find("auc:MeasureName", namespaces=tree.nsmap).text for m in chilled_water_hot_water_and_steam_distribution_systems},
286285
)
287286

287+
def test_build_xml_from_property_with_measures_and_meters_org_settings(self):
288+
# Set Up
289+
self.org.audit_template_export_meters = False
290+
self.org.audit_template_export_measures = False
291+
self.org.save()
292+
293+
self.element1 = self.element_factory.get_element(
294+
property=self.view1.property, code=Uniformat.objects.filter(code__in=SCOPE_ONE_EMISSION_CODES)[1]
295+
)
296+
self.element2 = self.element_factory.get_element(
297+
property=self.view1.property, code=Uniformat.objects.filter(code__in=SCOPE_ONE_EMISSION_CODES)[2]
298+
)
299+
300+
self.meter = Meter.objects.create(property_id=self.view1.property_id, type=Meter.ELECTRICITY_GRID)
301+
MeterReading.objects.create(
302+
start_time=datetime(2019, 1, 1, 0, 0, 0, tzinfo=tz.utc),
303+
end_time=datetime(2019, 2, 1, 0, 0, 0, tzinfo=tz.utc),
304+
reading=123,
305+
meter_id=self.meter.id,
306+
conversion_factor=1,
307+
)
308+
309+
# Action
310+
at = AuditTemplate(self.org.id)
311+
response = at.build_xml(self.state1, "Demo City Report", self.state1.pm_property_id)
312+
313+
# Assert
314+
# # is tree
315+
self.assertEqual(tuple, type(response))
316+
tree = etree.XML(response[0])
317+
318+
# # has 1 scenario
319+
scenarios = tree.findall("auc:Facilities/auc:Facility/auc:Reports/auc:Report/auc:Scenarios/auc:Scenario", namespaces=tree.nsmap)
320+
self.assertEqual(1, len(scenarios))
321+
scenario = scenarios[0]
322+
323+
# # scenario has 0 meters
324+
meters = scenario.findall("auc:ResourceUses/auc:ResourceUse", namespaces=tree.nsmap)
325+
self.assertEqual(0, len(meters))
326+
327+
# # scenario has 0 meter readings
328+
meter_readings = scenario.findall("auc:TimeSeriesData/auc:TimeSeries", namespaces=tree.nsmap)
329+
self.assertEqual(0, len(meter_readings))
330+
331+
# # tree has 0 measures
332+
measures = tree.findall("auc:Facilities/auc:Facility/auc:Measures", namespaces=tree.nsmap)
333+
self.assertEqual(0, len(measures))
334+
288335
@mock.patch("requests.request")
289336
def test_export_to_audit_template(self, mock_request):
290337
"""

seed/views/v3/organizations.py

+10
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def _dict_org(request, organizations):
153153
"audit_template_user": o.audit_template_user,
154154
"audit_template_password": decrypt(o.audit_template_password)[0] if o.audit_template_password else "",
155155
"audit_template_city_id": o.audit_template_city_id,
156+
"audit_template_export_meters": o.audit_template_export_meters,
157+
"audit_template_export_measures": o.audit_template_export_measures,
156158
"audit_template_conditional_import": o.audit_template_conditional_import,
157159
"audit_template_report_type": o.audit_template_report_type,
158160
"audit_template_status_types": o.audit_template_status_types,
@@ -657,6 +659,14 @@ def warn_bad_units(kind, unit_string):
657659
if audit_template_city_id != org.audit_template_city_id:
658660
org.audit_template_city_id = audit_template_city_id
659661

662+
audit_template_export_meters = posted_org.get("audit_template_export_meters", False)
663+
if audit_template_export_meters != org.audit_template_export_meters:
664+
org.audit_template_export_meters = audit_template_export_meters
665+
666+
audit_template_export_measures = posted_org.get("audit_template_export_measures", False)
667+
if audit_template_export_measures != org.audit_template_export_measures:
668+
org.audit_template_export_measures = audit_template_export_measures
669+
660670
audit_template_conditional_import = posted_org.get("audit_template_conditional_import", False)
661671
if audit_template_conditional_import != org.audit_template_conditional_import:
662672
org.audit_template_conditional_import = audit_template_conditional_import

0 commit comments

Comments
 (0)