Skip to content

Commit

Permalink
Improve Column list profile creation (#4646)
Browse files Browse the repository at this point in the history
* Improve Column list profile creation

* lint

---------

Co-authored-by: Katherine Fleming <2205659+kflemin@users.noreply.github.com>
  • Loading branch information
haneslinger and kflemin committed Apr 25, 2024
1 parent 9433699 commit 355c92d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
13 changes: 2 additions & 11 deletions seed/static/seed/js/controllers/inventory_settings_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,23 +290,14 @@ angular.module('BE.seed.controller.inventory_settings', []).controller('inventor
};

$scope.newProfile = () => {
const columns = [];
const derived_columns = [];
for (const column in currentColumns) {
if (column.derived_column) {
derived_columns.push(column);
} else {
columns.push(column);
}
}
const modalInstance = $uibModal.open({
templateUrl: `${urls.static_url}seed/partials/settings_profile_modal.html`,
controller: 'settings_profile_modal_controller',
resolve: {
action: () => 'new',
data: {
columns,
derived_columns
columns: currentColumns(),
derived_columns: []
},
profile_location: () => 'List View Profile',
inventory_type: () => ($scope.inventory_type === 'properties' ? 'Property' : 'Tax Lot')
Expand Down
31 changes: 31 additions & 0 deletions seed/tests/test_column_list_profiles_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from seed.landing.models import SEEDUser as User
from seed.models import Column
from seed.models.derived_columns import DerivedColumn
from seed.test_helpers.fake import FakeColumnListProfileFactory
from seed.tests.util import AccessLevelBaseTestCase, DeleteModelsTestCase
from seed.utils.organizations import create_organization
Expand Down Expand Up @@ -74,6 +75,36 @@ def test_create_column_profile(self):
self.assertEqual(data["data"]["inventory_type"], "Property")
self.assertEqual(data["data"]["profile_location"], "List View Profile")

def test_create_column_profile_with_derived_column(self):
self.derived_column = DerivedColumn.objects.create(
name="dc",
expression="$a + 10",
organization=self.org,
inventory_type=0,
)
self.payload_data["derived_columns"].append(
{
"column_name": "dc",
"derived_column": True,
"id": self.derived_column.id,
"order": 4,
"pinned": False,
"table_name": "PropertyState",
}
)

response = self.client.post(
reverse("api:v3:column_list_profiles-list") + "?organization_id=" + str(self.org.id),
data=json.dumps(self.payload_data),
content_type="application/json",
)
data = json.loads(response.content)
self.assertEqual(data["status"], "success")
self.assertEqual(len(data["data"]["columns"]), 3)
self.assertEqual(len(data["data"]["derived_columns"]), 1)
self.assertEqual(data["data"]["inventory_type"], "Property")
self.assertEqual(data["data"]["profile_location"], "List View Profile")

def test_get_column_profile(self):
# Create two list settings
self.client.post(
Expand Down

0 comments on commit 355c92d

Please sign in to comment.