Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ angular.module('SEED.controller.portfolio_summary', [])
// if org has no salesforce configs, status will be 'error' and valid will be false
$scope.is_logged_into_salesforce = is_logged_into_salesforce.data.valid;
$scope.chart_initialized = false;
$scope.related_model_sort = false;

$scope.search_for_goals = (query) => {
const pattern = query.split('').join('.*');
Expand Down Expand Up @@ -506,7 +507,7 @@ angular.module('SEED.controller.portfolio_summary', [])
$scope.baseline_labels = labels;
$scope.build_labels('baseline', $scope.baseline_labels);
});
label_service.get_property_view_labels_by_cycle_goal($scope.organization.id, $scope.goal.id, $scope.cycle_goal.cycle.id).then((labels) => {
label_service.get_property_view_labels_by_cycle_goal($scope.organization.id, $scope.goal.id, $scope.cycle_goal.current_cycle.id).then((labels) => {
$scope.current_labels = labels;
$scope.build_labels('current', $scope.current_labels);
});
Expand Down Expand Up @@ -965,6 +966,8 @@ angular.module('SEED.controller.portfolio_summary', [])
const formatted_columns = format_cycle_columns(grid_columns);

$scope.column_filters = [];
$scope.column_sorts = [];
$scope.related_model_sort = false;
// parse the filters and sorts
for (const column of formatted_columns) {
// format column if cycle specific
Expand Down
4 changes: 2 additions & 2 deletions seed/static/seed/js/services/label_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ angular.module('SEED.service.label', []).factory('label_service', [
}
];

const get_property_view_labels_by_goal = (org_id, goal_id, cycle_id) => $http.get(
const get_property_view_labels_by_cycle_goal = (org_id, goal_id, cycle_id) => $http.get(
'/api/v3/property_view_labels/list_by_cycle_goal/',
{ params: { organization_id: org_id, goal_id, cycle_id } }
)
Expand All @@ -307,7 +307,7 @@ angular.module('SEED.service.label', []).factory('label_service', [
update_property_labels,
update_taxlot_labels,
get_available_colors,
get_property_view_labels_by_goal,
get_property_view_labels_by_cycle_goal,
lookup_label
};
}
Expand Down
61 changes: 42 additions & 19 deletions seed/tests/test_goals.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,23 +570,46 @@ def test_goal_data(self):
assert data["property_lookup"] == {str(self.view31.id): self.property3.id, str(self.view33.id): self.property3.id}

def test_related_filter(self):
alphabet = ["a", "c", "b", "d"]
questions = [
"Is this value correct?",
"Are these values correct?",
"Other or multiple flags; explain in Additional Notes field",
"Is this other value correct?",
]
booleans = [True, False, True, False]
for idx, goal_note in enumerate(self.root_cycle_goal.goal.goalnote_set.order_by("property_id").all()):
goal_note.resolution = alphabet[idx]
goal_note.question = questions[idx]
goal_note.passed_checks = booleans[idx]
goal_note.new_or_acquired = booleans[idx]
goal_note_values = {
self.property1.id: {
"resolution": "a",
"question": "Is this value correct?",
"passed_checks": True,
"new_or_acquired": True,
},
# Property 2 is not in root_goal and will be ignored
self.property2.id: {
"resolution": "b",
"question": "Are these values correct?",
"passed_checks": False,
"new_or_acquired": False,
},
self.property3.id: {
"resolution": "c",
"question": "Other or multiple flags; explain in Additional Notes field",
"passed_checks": True,
"new_or_acquired": True,
},
self.property4.id: {
"resolution": "d",
"question": "Is this other value correct?",
"passed_checks": False,
"new_or_acquired": False,
},
}

for goal_note in self.root_cycle_goal.goal.goalnote_set.select_related("property"):
for field, value in goal_note_values[goal_note.property_id].items():
setattr(goal_note, field, value)
goal_note.save()

for idx, historical_note in enumerate(HistoricalNote.objects.filter(property__in=self.root_cycle_goal.properties().order_by("id"))):
historical_note.text = alphabet[idx]
historical_note_values = {
self.property1.id: "x",
self.property3.id: "y",
self.property4.id: "z",
}
for historical_note in HistoricalNote.objects.filter(property__in=self.root_cycle_goal.properties()):
historical_note.text = historical_note_values.get(historical_note.property_id)
historical_note.save()

goal_note = self.root_cycle_goal.goal.goalnote_set.first()
Expand All @@ -610,22 +633,22 @@ def test_related_filter(self):
assert response.status_code == 200
response = response.json()
resolutions = [p["goal_note"]["resolution"] for p in response["properties"]]
assert resolutions == ["a", "b", "d"]
assert resolutions == ["a", "c", "d"]
# sort resolution descending
params = f"?organization_id={self.org.id}&order_by=-property__goal_note__resolution"
url = path + params
response = self.client.put(url, data=json.dumps(data), content_type="application/json")
response = response.json()
resolutions = [p["goal_note"]["resolution"] for p in response["properties"]]
assert resolutions == ["d", "b", "a"]
assert resolutions == ["d", "c", "a"]

# sort historical note text
params = f"?organization_id={self.org.id}&order_by=property__historical_note__text"
params = f"?organization_id={self.org.id}&order_by=-property__historical_note__text"
url = path + params
response = self.client.put(url, data=json.dumps(data), content_type="application/json")
response = response.json()
historical_notes = [p["historical_note"]["text"] for p in response["properties"]]
assert historical_notes == ["a", "b", "c"]
assert historical_notes == ["z", "y", "x"]

# sort question
params = f"?organization_id={self.org.id}&order_by=property__goal_note__question"
Expand Down
15 changes: 14 additions & 1 deletion seed/tests/test_property_view_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def setUp(self):
self.pvl6 = PropertyViewLabel.objects.create(propertyview=self.view6, statuslabel=labels[4], goal=self.goal2)

def test_property_view_label_viewset(self):
url = reverse_lazy("api:v3:property_view_labels-list-by-goal")
url = reverse_lazy("api:v3:property_view_labels-list-by-cycle-goal")
params = {"organization_id": self.org.id, "goal_id": self.goal1.id, "cycle_id": self.cycle_goal.current_cycle.id}
response = self.client.get(url, params, content_type="application/json")
labels = response.json()
Expand All @@ -93,3 +93,16 @@ def test_property_view_label_viewset(self):
assert labels[1]["goal"] is None
assert labels[2]["goal"] == self.goal1.id
assert labels[3]["goal"] == self.goal1.id

def test_list_by_cycle_goal_returns_goal_and_unattached_labels(self):
url = reverse_lazy("api:v3:property_view_labels-list-by-cycle-goal")
params = {"organization_id": self.org.id, "goal_id": self.goal1.id, "cycle_id": self.goal1.baseline_cycle.id}

response = self.client.get(url, params, content_type="application/json")
assert response.status_code == 200

labels = response.json()
assert len(labels) == 4
goals = [label["goal"] for label in labels]
assert goals.count(None) == 2
assert goals.count(self.goal1.id) == 2
2 changes: 1 addition & 1 deletion seed/views/v3/property_view_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PropertyViewLabelViewSet(ModelViewSetWithoutPatch, OrgMixin):
]
)
@action(detail=False, methods=["GET"])
def list_by_goal(self, request):
def list_by_cycle_goal(self, request):
"""
Return property view labels that are attached to the passed cycle and
a. unattached to any goal
Expand Down
Loading