Skip to content

Commit 05d2a0c

Browse files
committed
fix(agenda): copy location information across to generated instance
1 parent 1e22368 commit 05d2a0c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

agenda/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def generate_occurrences(self, parent, from_datetime, to_datetime):
8787
user=parent.user,
8888
item_title=parent.item_title,
8989
item_details=parent.item_details,
90+
location=parent.location,
9091
)
9192
created.append(agenda)
9293

@@ -267,7 +268,11 @@ def save(self, *args, **kwargs):
267268
)
268269

269270
# Send an email to the user when the event is created
270-
if self.type != "chore" and self._state.adding and self.recurrence_parent is None:
271+
if (
272+
self.type != "chore"
273+
and self._state.adding
274+
and self.recurrence_parent is None
275+
):
271276
try:
272277
EmailMessage(
273278
"[Agenda] " + self.item_title,

agenda/tests/test_commands.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.core.management import call_command
77
from django.test import TestCase
88

9+
from acl.models import Location
910
from agenda.models import Agenda
1011
from chores.tests.factories import UserFactory
1112

@@ -38,3 +39,30 @@ def test_agenda_generate_recurring_events(self):
3839
# Verify that no emails were sent for automatically generated chores
3940
self.assertEqual(len(mail.outbox), 1)
4041

42+
@time_machine.travel("2025-05-06 10:00")
43+
def test_agenda_generate_recurring_events_with_location(self):
44+
location = Location.objects.create(name="Test Location")
45+
46+
# Add an Agenda item with a rrule defined
47+
Agenda.objects.create(
48+
user=self.user,
49+
item_title="Test Agenda",
50+
item_details="Test Description",
51+
startdatetime=datetime(2025, 5, 3, 8, 0, tzinfo=timezone.utc),
52+
enddatetime=datetime(2025, 5, 3, 16, 0, tzinfo=timezone.utc),
53+
recurrences="FREQ=DAILY;INTERVAL=1",
54+
location=location,
55+
)
56+
57+
stdout = StringIO()
58+
call_command("agenda_generate_recurring_events", stdout=stdout)
59+
call_command("agenda_generate_recurring_events", stdout=StringIO())
60+
61+
items = Agenda.objects.all()
62+
print(stdout.getvalue())
63+
self.assertIn("Generated 31 recurring events", stdout.getvalue())
64+
self.assertEqual(len(items), 32)
65+
66+
# Verify that location is set on the generated agenda items
67+
for item in items:
68+
self.assertEqual(item.location, location)

0 commit comments

Comments
 (0)