Repository: akvo/akvo-rsr

Issue:
Bug: Baseline comment inheritance
### What were you doing?

Change baseline comment of an indicator on a parent project

### What should've happened?

The baseline comment on child projects should inherit the changes

### My environment

_No response_

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/akvo/rsr/models/project.py b/akvo/rsr/models/project.py
--- a/akvo/rsr/models/project.py
+++ b/akvo/rsr/models/project.py
@@ -1539,6 +1539,7 @@ def copy_indicator(self, result, source_indicator, set_parent=True):
             export_to_iati=source_indicator.export_to_iati,
             scores=source_indicator.scores,
             order=source_indicator.order,
+            baseline_comment=source_indicator.baseline_comment,
         )
         if set_parent:
             indicator, created = Indicator.objects.update_or_create(
@@ -1550,7 +1551,7 @@ def copy_indicator(self, result, source_indicator, set_parent=True):
             indicator = Indicator.objects.create(result=result, **data)
             created = True
 
-        fields = ['baseline_year', 'baseline_value', 'baseline_comment']
+        fields = ['baseline_year', 'baseline_value']
         self._update_fields_if_not_child_updated(source_indicator, indicator, fields)
 
         if not created:
@@ -1584,12 +1585,12 @@ def update_indicator(self, result, parent_indicator):
             return
 
         update_fields = ['title', 'measure', 'ascending', 'type', 'export_to_iati', 'description',
-                         'order', 'scores']
+                         'order', 'scores', 'baseline_comment']
         for field in update_fields:
             setattr(child_indicator, field, getattr(parent_indicator, field))
         child_indicator.save(update_fields=update_fields)
 
-        fields = ['baseline_year', 'baseline_value', 'baseline_comment']
+        fields = ['baseline_year', 'baseline_value']
         self._update_fields_if_not_child_updated(parent_indicator, child_indicator, fields)
 
     def copy_period(self, indicator, source_period, set_parent=True):
@@ -1659,7 +1660,11 @@ def _update_fields_if_not_child_updated(self, parent, child, fields):
         """Copy the specified fields from parent to child, when empty on the child."""
         for field in fields:
             parent_value = getattr(parent, field)
-            if not getattr(child, field) and parent_value:
+            child_value = getattr(child, field)
+            if isinstance(child_value, str):
+                # cleanup unicode non-printing space
+                child_value = child_value.replace(u'\u200b', '')
+            if not child_value and parent_value:
                 setattr(child, field, parent_value)
 
         child.save()


Test patch:
diff --git a/akvo/rsr/tests/results_framework/test_results_framework.py b/akvo/rsr/tests/results_framework/test_results_framework.py
--- a/akvo/rsr/tests/results_framework/test_results_framework.py
+++ b/akvo/rsr/tests/results_framework/test_results_framework.py
@@ -274,6 +274,34 @@ def test_child_indicator_state_not_overwritten_after_change(self):
         self.indicator.baseline_comment = 'comment'
         self.indicator.save()
 
+        # Then
+        parent_indicator = Indicator.objects.get(id=self.indicator.id)
+        child_indicator = Indicator.objects.get(result__project=self.child_project,
+                                                parent_indicator=parent_indicator)
+        self.assertEqual(child_indicator.title, parent_indicator.title)
+        self.assertEqual(child_indicator.measure, parent_indicator.measure)
+        self.assertEqual(child_indicator.ascending, parent_indicator.ascending)
+        self.assertEqual(child_indicator.baseline_year, 2002)
+        self.assertEqual(child_indicator.baseline_value, new_value)
+        self.assertEqual(child_indicator.baseline_comment, parent_indicator.baseline_comment)
+
+    def test_overwrite_child_indicator_unicode_empty_space(self):
+        # Given
+        child_indicator = Indicator.objects.get(result__project=self.child_project,
+                                                parent_indicator=self.indicator)
+        unicode_empty = u'\u200b'
+        child_indicator.baseline_value = unicode_empty
+        child_indicator.baseline_comment = unicode_empty
+        child_indicator.baseline_year = 2002
+        child_indicator.save()
+
+        # When
+        new_value = 'test'
+        self.indicator.baseline_year = 2010
+        self.indicator.baseline_value = new_value
+        self.indicator.baseline_comment = new_value
+        self.indicator.save()
+
         # Then
         parent_indicator = Indicator.objects.get(id=self.indicator.id)
         child_indicator = Indicator.objects.get(result__project=self.child_project,