Repository: akvo/akvo-rsr

Issue:
Reporting org should be shown as the first partner
## Test plan

GIVEN a project
WHEN the project has a reporting partner that is not allowed to create projects
AND a different partner that is allowed to create projects
THEN the reporting partner should be the primary organisation (as shown on the project page and in the project list)
## Issue description

We currently always show the first partner that is allowed to create or publish a project as the primary organisation. However, this is not always the case and the partner team expects the reporting organisation to be shown as the primary partner.



Discussion:

Resolving patch:
diff --git a/akvo/rsr/migrations/0042_auto_20153011_1450.py b/akvo/rsr/migrations/0042_auto_20153011_1450.py
new file mode 100644
--- /dev/null
+++ b/akvo/rsr/migrations/0042_auto_20153011_1450.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+from ..models.project import Project
+
+def change_primary_organisations(apps, schema_editor):
+    Project = apps.get_model("rsr", "Project")
+
+    for project in Project.objects.all():
+        primary_organisation = None
+
+        # Pick the reporting org first
+        if project.partnerships.filter(iati_organisation_role=101):
+            primary_organisation = project.partnerships.filter(
+                iati_organisation_role=101)[0].organisation
+        
+        # Otherwise, pick the partner that can publish the project
+        elif project.partners.filter(can_create_projects=True):
+            primary_organisation = project.partners.filter(can_create_projects=True)[0]
+
+        # Otherwise, grab the first accountable partner we find
+        elif project.partnerships.filter(iati_organisation_role=2):
+            primary_organisation = project.partnerships.filter(
+                iati_organisation_role=2)[0].organisation
+
+        # Panic mode: grab the first partner we find
+        elif project.partners.all():
+            primary_organisation = project.partners.all()[0]
+
+        project.primary_organisation = primary_organisation
+        project.save(update_fields=['primary_organisation'])
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('rsr', '0041_auto_20151116_1250'),
+    ]
+
+    operations = [
+        migrations.RunPython(
+            change_primary_organisations,
+        ),
+    ]
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
@@ -881,12 +881,12 @@ def find_primary_organisation(self):
         """
         This method tries to return the "managing" partner organisation.
         """
-        # Pick the partner that can publish the project first
-        if self.publishing_orgs:
-            return self.publishing_orgs[0]
-        # Otherwise, if we have a reporting-org then we choose that
+        # Pick the reporting org first
         if self.reporting_org:
             return self.reporting_org
+        # Otherwise, pick the partner that can publish the project
+        if self.publishing_orgs:
+            return self.publishing_orgs[0]
         # Otherwise, grab the first accountable partner we find
         elif self.support_partners():
             return self.support_partners()[0]


Test patch: