From fe8c965783e0bd4a8ce01fee1a955e1825f7b430 Mon Sep 17 00:00:00 2001
From: Judit Foglszinger <urbec@debian.org>
Date: Mon, 15 Feb 2021 07:19:55 +0700
Subject: [PATCH 1/2] Not taking AM approved processes into account when
 calculating free slots, Closes #956898

---
 backend/models.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/backend/models.py b/backend/models.py
index 6262acba..a6e5c08d 100644
--- a/backend/models.py
+++ b/backend/models.py
@@ -826,11 +826,18 @@ class AM(models.Model):
                 unassigned_by__isnull=True, process__frozen_by__isnull=True,
                 process__approved_by__isnull=True,
                 process__closed_time__isnull=True).select_related("am"):
-            am = ams[p.am]
-            if p.paused:
-                am.proc_held.append(p)
-            else:
-                am.proc_active.append(p)
+            am_ok = None
+            # only take into account processes not yet approved by AM
+            for requirement in p.process.requirements.all():
+                if requirement.type == "am_ok":
+                    am_ok = requirement
+                    break
+            if am_ok is not None and am_ok.approved_time is None:
+                am = ams[p.am]
+                if p.paused:
+                    am.proc_held.append(p)
+                else:
+                    am.proc_active.append(p)
 
         res = []
         for am in list(ams.values()):
-- 
2.29.2

