Fix merging of organisations
authorMagnus Hagander <magnus@hagander.net>
Sat, 26 Sep 2020 14:59:23 +0000 (16:59 +0200)
committerMagnus Hagander <magnus@hagander.net>
Sat, 26 Sep 2020 15:00:26 +0000 (17:00 +0200)
This has been broken since the OneToOne change in 2016 and since the
addition of pugs in 2013. Clearly not much used functionality.

pgweb/core/views.py

index b5b93151ff0ea0e01616470cb0d81ab30b30e474..9684a08253c8a76afaebf5d208f255286bf5bbd0 100644 (file)
@@ -590,12 +590,18 @@ def admin_mergeorg(request):
             for p in f.product_set.all():
                 p.org = t
                 p.save()
-            for p in f.professionalservice_set.all():
-                p.organisation = t
+            if hasattr(f, 'professionalservice'):
+                p = f.professionalservice
+                p.org = t
+                p.save()
+            for p in f.pug_set.all():
+                p.org = t
                 p.save()
             # Now that everything is moved, we can delete the organisation
             f.delete()
 
+            messages.info(request, "Organisations merged")
+
             return HttpResponseRedirect("/admin/core/organisation/")
         # Else fall through to re-render form with errors
     else: