Skip to content
Snippets Groups Projects
Commit 00591c66 authored by Hubert Van de Walle (huvw)'s avatar Hubert Van de Walle (huvw)
Browse files

[FIX] calendar: duplicated emails when creating allday meeting


Steps to reproduce:

  - Switch to debug mode
  - Go to calendar
  - Create an allday event in the future named test
  - Add an attendee with an email address
  - Save
  - Go to Settings > Technical > Email > Emails

  Two emails have been sent:
  * Invitation to test
  * test: Date updated

Cause of the issue:

  The method `_inverse_dates` is called when creating an event,
  triggering a write on the start field.
  This then causes an update email to be sent

Solution:

  Add a context key and don't send the update email if it is present

opw-2841276

closes odoo/odoo#100275

Signed-off-by: default avatarArnaud Joset <arj@odoo.com>
parent 23a18bc1
Branches
Tags
No related merge requests found
......@@ -711,7 +711,7 @@ class Meeting(models.Model):
current_attendees = self.filtered('active').attendee_ids
if 'partner_ids' in values:
(current_attendees - previous_attendees)._send_mail_to_attendees('calendar.calendar_template_meeting_invitation')
if 'start' in values:
if not self.env.context.get('is_calendar_event_new') and 'start' in values:
start_date = fields.Datetime.to_datetime(values.get('start'))
# Only notify on future events
if start_date and start_date >= fields.Datetime.now():
......@@ -721,6 +721,9 @@ class Meeting(models.Model):
@api.model_create_multi
def create(self, vals_list):
# Prevent sending update notification when _inverse_dates is called
self = self.with_context(is_calendar_event_new=True)
vals_list = [ # Else bug with quick_create when we are filter on an other user
dict(vals, user_id=self.env.user.id) if not 'user_id' in vals else vals
for vals in vals_list
......@@ -785,7 +788,7 @@ class Meeting(models.Model):
if len(event.alarm_ids) > 0:
self.env['calendar.alarm_manager']._notify_next_alarm(event.partner_ids.ids)
return events
return events.with_context(is_calendar_event_new=False)
def _read(self, fields):
if self.env.is_system():
......
......@@ -30,6 +30,20 @@ class TestEventNotifications(SavepointCase, MailCase):
}):
self.event.partner_ids = self.partner
def test_message_invite_allday(self):
with self.assertSinglePostNotifications([{'partner': self.partner, 'type': 'inbox'}], {
'message_type': 'user_notification',
'subtype': 'mail.mt_note',
}):
self.env['calendar.event'].with_context(mail_create_nolog=True).create([{
'name': 'Meeting',
'allday': True,
'start_date': fields.Date.today() + relativedelta(days=7),
'stop_date': fields.Date.today() + relativedelta(days=8),
'partner_ids': [(4, self.partner.id)],
}])
def test_message_invite_self(self):
with self.assertNoNotifications():
self.event.with_user(self.user).partner_ids = self.partner
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment