Browse Source

during batch sms skip creation of past one

tripeur 2 years ago
parent
commit
8355f72b19
1 changed files with 5 additions and 1 deletions
  1. 5 1
      app/api/endpoints/project.py

+ 5 - 1
app/api/endpoints/project.py

@@ -1,4 +1,4 @@
-from datetime import timedelta
+from datetime import timedelta, datetime
 from uuid import UUID
 
 from fastapi import APIRouter, Depends, HTTPException
@@ -192,6 +192,7 @@ async def create_sms_batch(
     # Get all slots
     slots = session.execute(select(Slot).where(Slot.project_id == project_id))
     sms_list = []
+    now = datetime.now()
     for slot in slots.scalars():
         # Replace the slot placeholder by their value
         slot_content = (
@@ -202,6 +203,9 @@ async def create_sms_batch(
             .replace("{respo}", slot.responsible_contact)
         )
         sending_time = slot.starting_time - timedelta(minutes=sms_batch.delta_t)
+        # Skip SMS that should have been send before now
+        if sending_time < now:
+            continue
         for volunteer in slot.volunteers:
             if not volunteer.automatic_sms:
                 continue