Skip to content

Commit

Permalink
Merge pull request #2632 from SEED-platform/feat/fix-merge-option
Browse files Browse the repository at this point in the history
Feat/fix merge option
  • Loading branch information
Ryo committed Mar 24, 2022
2 parents 4744938 + 073f0d7 commit a6ffde1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
3 changes: 1 addition & 2 deletions seed/static/seed/partials/inventory_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ <h2>
</li>

<li role="menuitem">
<!-- ng-click="open_match_merge_link_warning_modal(match_merge_link_record, 'manual')" -->
<a style="opacity:.5;cursor:not-allowed;">Merge and Link Matches</a>
<a ng-click="open_match_merge_link_warning_modal(match_merge_link_record, 'manual')">Merge and Link Matches</a>
</li>

<li class="divider"></li>
Expand Down
63 changes: 32 additions & 31 deletions seed/tests/test_match_existing.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,39 +448,39 @@ def test_match_merge_link_rolls_up_existing_property_matches_in_updated_state_or

"""
Verify everything's rolled up to one -View with precedence given to
manual merge -View with '1st Oldest City'. '1st Oldest City' is expected
manual merge -View with '3rd Oldest City'. '3rd Oldest City' is expected
to be final City value since this rollup should ignore Merge Protection.
"""
self.assertEqual(PropertyView.objects.count(), 1)
only_view = PropertyView.objects.get()
self.assertEqual(only_view.state.city, '1st Oldest City')
self.assertEqual(only_view.state.extra_data['state_order'], 'first')
self.assertEqual(only_view.state.city, '3rd Oldest City')
self.assertEqual(only_view.state.extra_data['state_order'], 'third')

"""
Undoing 1 rollup merge should expose a set -State having
'3rd Oldest City' and state_order of 'third'.
'2nd Oldest City' and state_order of 'second'.
"""
rollback_unmerge_url_1 = reverse('api:v3:properties-unmerge', args=[only_view.id]) + '?organization_id={}'.format(self.org.pk)
response = self.client.put(rollback_unmerge_url_1, content_type='application/json')
self.assertEqual(200, response.status_code)
self.assertEqual('success', json.loads(response.content).get('status'))

rollback_view_1 = PropertyView.objects.prefetch_related('state').exclude(state__city='1st Oldest City').get()
self.assertEqual(rollback_view_1.state.city, '3rd Oldest City')
self.assertEqual(rollback_view_1.state.extra_data['state_order'], 'third')
rollback_view_1 = PropertyView.objects.prefetch_related('state').exclude(state__city='3rd Oldest City').get()
self.assertEqual(rollback_view_1.state.city, '2nd Oldest City')
self.assertEqual(rollback_view_1.state.extra_data['state_order'], 'second')

"""
Undoing another rollup merge should expose a set -State having
'2nd Oldest City' and state_order of 'second'.
'4th Oldest City' and state_order of 'fourth'.
"""
rollback_unmerge_url_2 = reverse('api:v3:properties-unmerge', args=[rollback_view_1.id]) + '?organization_id={}'.format(self.org.pk)
response = self.client.put(rollback_unmerge_url_2, content_type='application/json')
self.assertEqual(200, response.status_code)
self.assertEqual('success', json.loads(response.content).get('status'))

rollback_view_2 = PropertyView.objects.prefetch_related('state').exclude(state__city__in=['1st Oldest City', '3rd Oldest City']).get()
self.assertEqual(rollback_view_2.state.city, '2nd Oldest City')
self.assertEqual(rollback_view_2.state.extra_data['state_order'], 'second')
rollback_view_2 = PropertyView.objects.prefetch_related('state').exclude(state__city__in=['3rd Oldest City', '2nd Oldest City']).get()
self.assertEqual(rollback_view_2.state.city, '4th Oldest City')
self.assertEqual(rollback_view_2.state.extra_data['state_order'], 'fourth')

def test_match_merge_link_ignores_properties_with_unpopulated_matching_criteria(self):
base_details = {
Expand Down Expand Up @@ -591,35 +591,34 @@ def test_match_merge_link_rolls_up_existing_taxlot_matches_in_updated_state_orde

"""
Verify everything's rolled up to one -View with precedence given to
manual merge -View with '1st Oldest City'. '1st Oldest City' is expected
to be final City value since this rollup should ignore Merge Protection.
the reverse order of the merged -State. 3rd City will be given precedecnce
"""
self.assertEqual(TaxLotView.objects.count(), 1)
only_view = TaxLotView.objects.get()
self.assertEqual(only_view.state.city, '1st Oldest City')
self.assertEqual(only_view.state.extra_data['state_order'], 'first')
self.assertEqual(only_view.state.city, '3rd Oldest City')
self.assertEqual(only_view.state.extra_data['state_order'], 'third')

"""
Undoing 1 rollup merge should expose a set -State having
'3rd Oldest City' and state_order of 'third'.
'2nd Oldest City' and state_order of 'second'.
"""
rollback_unmerge_url_1 = reverse('api:v3:taxlots-unmerge', args=[only_view.id]) + '?organization_id={}'.format(self.org.pk)
self.client.post(rollback_unmerge_url_1, content_type='application/json')

rollback_view_1 = TaxLotView.objects.prefetch_related('state').exclude(state__city='1st Oldest City').get()
self.assertEqual(rollback_view_1.state.city, '3rd Oldest City')
self.assertEqual(rollback_view_1.state.extra_data['state_order'], 'third')
rollback_view_1 = TaxLotView.objects.prefetch_related('state').exclude(state__city='3rd Oldest City').get()
self.assertEqual(rollback_view_1.state.city, '2nd Oldest City')
self.assertEqual(rollback_view_1.state.extra_data['state_order'], 'second')

"""
Undoing another rollup merge should expose a set -State having
'2nd Oldest City' and state_order of 'second'.
'4th Oldest City' and state_order of 'fourth'.
"""
rollback_unmerge_url_2 = reverse('api:v3:taxlots-unmerge', args=[rollback_view_1.id]) + '?organization_id={}'.format(self.org.pk)
self.client.post(rollback_unmerge_url_2, content_type='application/json')

rollback_view_2 = TaxLotView.objects.prefetch_related('state').exclude(state__city__in=['1st Oldest City', '3rd Oldest City']).get()
self.assertEqual(rollback_view_2.state.city, '2nd Oldest City')
self.assertEqual(rollback_view_2.state.extra_data['state_order'], 'second')
rollback_view_2 = TaxLotView.objects.prefetch_related('state').exclude(state__city__in=['3rd Oldest City', '2nd Oldest City']).get()
self.assertEqual(rollback_view_2.state.city, '4th Oldest City')
self.assertEqual(rollback_view_2.state.extra_data['state_order'], 'fourth')

def test_match_merge_link_ignores_taxlots_with_unpopulated_matching_criteria(self):
base_details = {
Expand Down Expand Up @@ -796,8 +795,9 @@ def test_match_merge_link_for_properties(self):

cycle_1_cities = list(cycle_1_views.prefetch_related('state').values_list('state__city', flat=True))
expected_cities_1 = [
'1st Match - Cycle 1 - City 1', # ps_11 took precedence over ps_12, since the provided -View was ps_11's -View
'Unmatched City - Cycle 1'
'Unmatched City - Cycle 1',
'1st Match - Cycle 1 - City 2' # ps_11 took precedence over ps_12, since the provided -View was ps_11's -View
# Update: precedence is given in reverse order of merge
]
self.assertCountEqual(expected_cities_1, cycle_1_cities)

Expand All @@ -807,8 +807,9 @@ def test_match_merge_link_for_properties(self):

cycle_2_cities = list(cycle_2_views.prefetch_related('state').values_list('state__city', flat=True))
expected_cities_2 = [
'1st Match - Cycle 2 - City 2', # ps_22 was explicitly given precedence
'Unmatched City - Cycle 2'
'Unmatched City - Cycle 2',
'1st Match - Cycle 2 - City 2' # ps_22 was explicitly given precedence.
# Update: precedence is given in reverse order of merge
]
self.assertCountEqual(expected_cities_2, cycle_2_cities)

Expand Down Expand Up @@ -952,8 +953,8 @@ def test_match_merge_link_for_taxlots(self):

cycle_1_cities = list(cycle_1_views.prefetch_related('state').values_list('state__city', flat=True))
expected_cities_1 = [
'1st Match - Cycle 1 - City 1', # tls_11 took precedence over tls_12, since tls_11's -View took precedence
'Unmatched City - Cycle 1'
'Unmatched City - Cycle 1',
'1st Match - Cycle 1 - City 2' # precedence given in reverse order of merge
]
self.assertCountEqual(expected_cities_1, cycle_1_cities)

Expand All @@ -963,8 +964,8 @@ def test_match_merge_link_for_taxlots(self):

cycle_2_cities = list(cycle_2_views.prefetch_related('state').values_list('state__city', flat=True))
expected_cities_2 = [
'1st Match - Cycle 2 - City 3', # tls_23 took precedence
'Unmatched City - Cycle 2'
'Unmatched City - Cycle 2',
'1st Match - Cycle 2 - City 3' # precedence given in reverse order of merge
]
self.assertCountEqual(expected_cities_2, cycle_2_cities)

Expand Down
5 changes: 3 additions & 2 deletions seed/utils/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ def _merge_matches_across_cycles(matching_views, org_id, given_state_id, StateCl
if given_state_id in ordered_ids:
# If the given -State ID is included, give it precedence and
# capture resulting merged_state ID to be returned
ordered_ids.remove(given_state_id)
ordered_ids.append(given_state_id)
# (disabled with https://github.com/SEED-platform/seed/issues/2624)
# ordered_ids.remove(given_state_id)
# ordered_ids.append(given_state_id)
merged_state = merge_states_with_views(ordered_ids, org_id, 'System Match', StateClass)
target_state_id = merged_state.id
else:
Expand Down

0 comments on commit a6ffde1

Please sign in to comment.