Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2307] Update actual values entered in project editor #2311

Merged
merged 5 commits into from
Jul 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions akvo/rsr/models/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def __unicode__(self):

return period_unicode

def save(self, *args, **kwargs):
def save(self, update_parents=True, *args, **kwargs):
"""Update the values of child periods, if a parent period is updated."""
# Update period when it's edited
if self.pk:
Expand All @@ -345,6 +345,13 @@ def save(self, *args, **kwargs):

child_period.save()

# Update parent actual values
if self.indicator.is_child_indicator() and self.actual_value != orig_period.actual_value and update_parents:
if self.parent_period().indicator.result.project.aggregate_children and \
self.indicator.result.project.aggregate_to_parent:
# self.parent_period().update_parent_actual_values(self.actual_value, orig_period.actual_value)
self.parent_period().update_actual_value(self.actual_value, True)

# Create a new period when it's added
else:
for child_indicator in self.indicator.child_indicators():
Expand Down Expand Up @@ -560,7 +567,7 @@ def update_actual_value(self, data, relative_data, comment=''):
new_parent_value = str(-old_actual) if old_is_decimal or new_is_decimal else ''

# Save new actual value of period
self.save(update_fields=['actual_value'])
self.save(update_fields=['actual_value'], update_parents=False)

# Update parent period
if parent and aggregate_to_parent and (old_is_decimal or new_is_decimal):
Expand Down
6 changes: 3 additions & 3 deletions akvo/rsr/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,9 +1322,9 @@ def import_results(self):
import_failed = 0
import_success = 1

if self.parents().count() == 1:
parent_project = self.parents()[0]
elif self.parents().count() == 0:
if self.parents_all().count() == 1:
parent_project = self.parents_all()[0]
elif self.parents_all().count() == 0:
return import_failed, 'Project does not have a parent project'
else:
return import_failed, 'Project has multiple parent projects'
Expand Down
2 changes: 1 addition & 1 deletion akvo/templates/myrsr/project_editor/section_5.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</div>
<div class="col-md-9">
<div class="help-block">
{% trans 'Import the results framework of the parent project' %}: <a href="{% url 'project-main' project.parents.0.pk %}" target="_blank">{{ project.parents.0.title }}</a>
{% trans 'Import the results framework of the parent project' %}: <a href="{% url 'project-main' project.parents_all.0.pk %}" target="_blank">{{ project.parents_all.0.title }}</a>
</div>
</div>
</div>
Expand Down