From edf747d16326aa9c4e768c06ac9fd36819198e03 Mon Sep 17 00:00:00 2001 From: Roman Karpovich Date: Thu, 21 Mar 2024 12:24:21 +0800 Subject: [PATCH] allow title modification for amendment process --- .../applications/partners/amendment_utils.py | 1 - src/etools/applications/partners/models.py | 7 +++++++ .../partners/tests/test_amendments.py | 21 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/etools/applications/partners/amendment_utils.py b/src/etools/applications/partners/amendment_utils.py index 50b0bc0207..6347c849ff 100644 --- a/src/etools/applications/partners/amendment_utils.py +++ b/src/etools/applications/partners/amendment_utils.py @@ -647,7 +647,6 @@ def full_snapshot_instance(instance, relations_to_copy, exclude_fields): 'partners.Intervention': [ 'modified', 'number', 'status', 'in_amendment', - 'title', 'sites', # submission diff --git a/src/etools/applications/partners/models.py b/src/etools/applications/partners/models.py index 52821ebe69..9126e0bfa2 100644 --- a/src/etools/applications/partners/models.py +++ b/src/etools/applications/partners/models.py @@ -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, @@ -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, diff --git a/src/etools/applications/partners/tests/test_amendments.py b/src/etools/applications/partners/tests/test_amendments.py index d8a74ef01f..6ed91c68a9 100644 --- a/src/etools/applications/partners/tests/test_amendments.py +++ b/src/etools/applications/partners/tests/test_amendments.py @@ -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')