From 4f28864617f7efa0f43c1bf775fb3246214df31b Mon Sep 17 00:00:00 2001 From: "Achraf (abz)" Date: Tue, 20 Oct 2020 15:01:00 +0000 Subject: [PATCH] [FIX] calendar: Dont send mail to attendees when the event date is past Issue - Install "Calender" - Install "Google Calendar" - Try to sync google in "Calendar" Every created events will trigger the sending mail to attendees even if the event date is past Cause 'events' was not filtered Solution Filter 'events' to get all the events that have not yet happened opw-2358123 closes odoo/odoo#60414 X-original-commit: 3b1df8f57e0cd342fe7f9ff7bd34100b2c821569 Signed-off-by: Nicolas Martinelli (nim) Signed-off-by: Achraf --- addons/calendar/models/calendar_event.py | 2 +- addons/calendar/tests/test_calendar.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/addons/calendar/models/calendar_event.py b/addons/calendar/models/calendar_event.py index f628558ae99..d28f1c308c4 100644 --- a/addons/calendar/models/calendar_event.py +++ b/addons/calendar/models/calendar_event.py @@ -720,7 +720,7 @@ class Meeting(models.Model): detached_events = event._apply_recurrence_values(recurrence_values) detached_events.active = False - events.attendee_ids._send_mail_to_attendees('calendar.calendar_template_meeting_invitation') + events.filtered(lambda event: event.start > fields.Datetime.now()).attendee_ids._send_mail_to_attendees('calendar.calendar_template_meeting_invitation') events._sync_activities(fields={f for vals in vals_list for f in vals.keys() }) # Notify attendees if there is an alarm on the created event, as it might have changed their diff --git a/addons/calendar/tests/test_calendar.py b/addons/calendar/tests/test_calendar.py index ab0f29752a2..a7a0988b4c0 100644 --- a/addons/calendar/tests/test_calendar.py +++ b/addons/calendar/tests/test_calendar.py @@ -258,7 +258,7 @@ class TestCalendar(SavepointCaseWithUserDemo): """ Check that mail are sent to the attendees on event creation Check that mail are sent to the added attendees on event edit - Check that mail are NOT sent to the attendees when detaching a recurring event + Check that mail are NOT sent to the attendees when the event date is past """ def _test_one_mail_per_attendee(self, partners): @@ -302,3 +302,16 @@ class TestCalendar(SavepointCaseWithUserDemo): # more email should be sent _test_one_mail_per_attendee(self, partners) + + # create a new event in the past + self.CalendarEvent.create({ + 'name': "NOmailTest", + 'allday': False, + 'recurrency': False, + 'partner_ids': partner_ids, + 'start': fields.Datetime.to_string(now - timedelta(days=10)), + 'stop': fields.Datetime.to_string(now - timedelta(days=9)), + }) + + # no more email should be sent + _test_one_mail_per_attendee(self, partners)