Skip to content

Commit

Permalink
Merge pull request #3688 from unicef/develop
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
robertavram authored Jun 13, 2024
2 parents 82d3942 + af578ef commit b84d062
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/etools/applications/partners/amendment_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,6 @@ def full_snapshot_instance(instance, relations_to_copy, exclude_fields):
'partners.Intervention': [
'modified',
'number', 'status', 'in_amendment',
'title',
'sites',

# submission
Expand Down
7 changes: 7 additions & 0 deletions src/etools/applications/partners/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2757,7 +2757,13 @@ def _copy_intervention(self):
self.amended_intervention.submission_date = timezone.now().date()
self.amended_intervention.save()

def clean_amended_intervention(self):
# strip amended prefix from title in case of modifications
self.amended_intervention.title = self.amended_intervention.title.replace('[Amended]', '').lstrip(' ')

def merge_amendment(self):
self.clean_amended_intervention()

merge_instance(
self.intervention,
self.amended_intervention,
Expand Down Expand Up @@ -2798,6 +2804,7 @@ def merge_amendment(self):
amended_intervention.delete()

def get_difference(self):
self.clean_amended_intervention()
return calculate_difference(
self.intervention,
self.amended_intervention,
Expand Down
21 changes: 21 additions & 0 deletions src/etools/applications/partners/tests/test_amendments.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,24 @@ def test_sync_budget_owner(self):
self.assertNotEqual(self.active_intervention.budget_owner, old_budget_owner)
self.assertEqual(active_amendment.amended_intervention.budget_owner, self.active_intervention.budget_owner)
self.assertEqual(completed_amendment.amended_intervention.budget_owner, old_budget_owner)

def test_update_title(self):
amendment = InterventionAmendmentFactory(
intervention=self.active_intervention,
kind=InterventionAmendment.KIND_NORMAL,
)

amendment.amended_intervention.title = '[Amended] New Title'
amendment.amended_intervention.save()

amendment.difference = amendment.get_difference()
amendment.merge_amendment()

self.assertDictEqual(
amendment.difference,
{
'title': {'diff': ('Active Intervention', 'New Title'), 'type': 'simple'}
},
)
self.active_intervention.refresh_from_db()
self.assertEqual(self.active_intervention.title, 'New Title')

0 comments on commit b84d062

Please sign in to comment.