Skip to content

Commit

Permalink
[FIX] calendar_monthly_multi: Make it work with latest Odoo commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tarteo committed Oct 4, 2024
1 parent fd98060 commit 0b0e660
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions calendar_monthly_multi/models/calendar_recurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CalendarRecurrence(models.Model):
)
day_ids = fields.Many2many(comodel_name="calendar.recurrence.day")

@api.depends("weekday", "rrule_type", "month_by")
@api.depends("weekday", "rrule_type", "month_by", "rrule")
def _compute_weekday_ids(self):
for recurrence in self.filtered(
lambda r: r.weekday != "custom"
Expand All @@ -54,7 +54,7 @@ def _compute_weekday_ids(self):
"calendar_monthly_multi.%s" % RRULE_WEEKDAYS[recurrence.weekday]
).ids

@api.depends("day_ids")
@api.depends("day_ids", "weekday_ids")
def _compute_rrule(self):
return super()._compute_rrule()

Expand Down
43 changes: 22 additions & 21 deletions calendar_monthly_multi/tests/test_recurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class TestRecurrence(TransactionCase):
def test_weekend_days(self):
base_event = self.env["calendar.event"].create(
self.env["calendar.event"].create(
{
"name": "Last weekend day",
"start": fields.Datetime.to_datetime("2023-09-01 12:00:00"),
Expand All @@ -19,8 +19,10 @@ def test_weekend_days(self):
"event_tz": "UTC",
}
)
# You probably wonder why we get the recurrence this way, it's because of this commit https://github.com/odoo/odoo/commit/43a774d68574e72fa4aabad65db42a03fac6e666#diff-6c4c124bfb9e4397bed7221c7534c8f877904775e9db4cf81f72b5430b36ad06R631
# I had to change it to this, because the created event is not the base event anymore. The same goes for the other ones
recurrence = self.env["calendar.recurrence"].search(
[("base_event_id", "=", base_event.id)]
[], limit=1, order="id desc"
)
self.assertEqual(len(recurrence.calendar_event_ids), 10)

Expand All @@ -45,7 +47,7 @@ def test_weekend_days(self):
)

def test_day(self):
base_event = self.env["calendar.event"].create(
self.env["calendar.event"].create(
{
"name": "Fourth day",
"start_date": fields.Date.to_date("2023-09-01"),
Expand All @@ -62,7 +64,7 @@ def test_day(self):
}
)
recurrence = self.env["calendar.recurrence"].search(
[("base_event_id", "=", base_event.id)]
[], limit=1, order="id desc"
)

self.assertEqual(len(recurrence.calendar_event_ids), 20)
Expand All @@ -75,7 +77,7 @@ def test_day(self):
)

def test_weekdays(self):
base_event = self.env["calendar.event"].create(
self.env["calendar.event"].create(
{
"name": "First workday (mo to fr)",
"start_date": fields.Date.to_date("2023-09-10"), # Skip for 2023-09
Expand All @@ -93,7 +95,7 @@ def test_weekdays(self):
}
)
recurrence = self.env["calendar.recurrence"].search(
[("base_event_id", "=", base_event.id)]
[], limit=1, order="id desc"
)
self.assertEqual(
len(recurrence.calendar_event_ids), 12
Expand All @@ -109,7 +111,7 @@ def test_weekdays(self):
)

def test_multi_dates(self):
base_event = self.env["calendar.event"].create(
self.env["calendar.event"].create(
{
"name": "Multi dates on 5th and 20th (interval 2)",
"start_date": fields.Date.to_date("2023-09-10"),
Expand All @@ -131,7 +133,7 @@ def test_multi_dates(self):
}
)
recurrence = self.env["calendar.recurrence"].search(
[("base_event_id", "=", base_event.id)]
[], limit=1, order="id desc"
)
self.assertEqual(len(recurrence.calendar_event_ids), 24)
some_recurrence = recurrence.calendar_event_ids.filtered(
Expand All @@ -155,7 +157,7 @@ def test_multi_dates(self):
def test_inverse_rrule_multi_date(self):
day_5 = self.ref("calendar_monthly_multi.day_5")
day_20 = self.ref("calendar_monthly_multi.day_20")
multi_date_event = self.env["calendar.event"].create(
self.env["calendar.event"].create(
{
"name": "Multi dates on 5th and 20th (interval 2)",
"start_date": fields.Date.to_date("2023-09-10"),
Expand All @@ -172,7 +174,7 @@ def test_inverse_rrule_multi_date(self):
}
)
recurrence = self.env["calendar.recurrence"].search(
[("base_event_id", "=", multi_date_event.id)]
[], limit=1, order="id desc"
)

multi_date_test = self.env["calendar.recurrence"].create(
Expand All @@ -190,7 +192,7 @@ def test_inverse_rrule_weekdays(self):
saturday = self.ref("calendar_monthly_multi.SA")
sunday = self.ref("calendar_monthly_multi.SU")

weekend_day_event = self.env["calendar.event"].create(
self.env["calendar.event"].create(
{
"name": "Weekend Day Test",
"start_date": fields.Date.to_date("2023-09-10"),
Expand All @@ -207,7 +209,7 @@ def test_inverse_rrule_weekdays(self):
}
)
recurrence = self.env["calendar.recurrence"].search(
[("base_event_id", "=", weekend_day_event.id)]
[], limit=1, order="id desc"
)

weekend_day_test = self.env["calendar.recurrence"].create(
Expand All @@ -219,7 +221,7 @@ def test_inverse_rrule_weekdays(self):
self.assertIn(sunday, weekend_day_test.weekday_ids.ids)
self.assertEqual(weekend_day_test.weekday, "weekend_day")

all_days_event = self.env["calendar.event"].create(
self.env["calendar.event"].create(
{
"name": "Weekday (any day) test",
"start_date": fields.Date.to_date("2023-09-10"),
Expand All @@ -236,9 +238,8 @@ def test_inverse_rrule_weekdays(self):
}
)
recurrence = self.env["calendar.recurrence"].search(
[("base_event_id", "=", all_days_event.id)]
[], limit=1, order="id desc"
)

all_days_test = self.env["calendar.recurrence"].create(
{"rrule": recurrence.rrule}
)
Expand All @@ -250,7 +251,7 @@ def test_inverse_rrule_weekdays(self):
self.assertIn(wednesday, all_days_test.weekday_ids.ids)
self.assertEqual(all_days_test.weekday, "day")

workday_event = self.env["calendar.event"].create(
self.env["calendar.event"].create(
{
"name": "Workday test",
"start_date": fields.Date.to_date("2023-09-10"),
Expand All @@ -267,7 +268,7 @@ def test_inverse_rrule_weekdays(self):
}
)
recurrence = self.env["calendar.recurrence"].search(
[("base_event_id", "=", workday_event.id)]
[], limit=1, order="id desc"
)

workday_test = self.env["calendar.recurrence"].create(
Expand All @@ -281,7 +282,7 @@ def test_inverse_rrule_weekdays(self):
self.assertNotIn(saturday, workday_test.weekday_ids.ids)
self.assertEqual(workday_test.weekday, "weekday")

custom_event = self.env["calendar.event"].create(
self.env["calendar.event"].create(
{
"name": "Custom test",
"start_date": fields.Date.to_date("2023-09-10"),
Expand All @@ -299,7 +300,7 @@ def test_inverse_rrule_weekdays(self):
}
)
recurrence = self.env["calendar.recurrence"].search(
[("base_event_id", "=", custom_event.id)]
[], limit=1, order="id desc"
)

custom_test = self.env["calendar.recurrence"].create(
Expand All @@ -313,7 +314,7 @@ def test_inverse_rrule_weekdays(self):
self.assertNotIn(sunday, custom_test.weekday_ids.ids)
self.assertEqual(custom_test.weekday, "custom")

normal_event = self.env["calendar.event"].create(
self.env["calendar.event"].create(
{
"name": "Normal test",
"start_date": fields.Date.to_date("2023-09-10"),
Expand All @@ -330,7 +331,7 @@ def test_inverse_rrule_weekdays(self):
}
)
recurrence = self.env["calendar.recurrence"].search(
[("base_event_id", "=", normal_event.id)]
[], limit=1, order="id desc"
)

normal_test = self.env["calendar.recurrence"].create(
Expand Down

0 comments on commit 0b0e660

Please sign in to comment.