diff options
| author | fw-bot <otis@odoo.com> | 2019-11-14 15:17:05 +0000 |
|---|---|---|
| committer | fw-bot <otis@odoo.com> | 2019-11-15 10:30:01 +0000 |
| commit | c5570c4e7d18453825125de00f0a00418cb07c48 (patch) | |
| tree | 8b84f380a1b5883d0cc47633c840fcaa49a3d7b8 /addons | |
| parent | bf87b4a758b3518e9a467f79879dacb0cb4f61c1 (diff) | |
[FIX] calendar: fix wrong date for recurring event emails
Reproduce this bug
- Install Calendar
- Create a recurring event starting at the date of yesterday
(later than your actual time)
- Set the recurrency to every day, 1 time (today)
- Click on the today's event
- Add attendees > Invitations > Send mail
- Run the mail queue manually (Technical > Scheduled actions)
The mail you sent are for the date of yesterday
The behavior is the same for the reminders
Cause
The mail are sent with the `_send_mail_to_attendees` method
who pass the attendee_id to the templates.
The `attendee_id.event_id` is always the first one.
This commit pass the correct event to the template via the context.
I replaced only the dates values in the template.
closes odoo/odoo#40320
X-original-commit: 1926c6cfea0e21842fbd71fd85629b13fce9b413
Signed-off-by: Jason Van Malder <jasonvanmalder@users.noreply.github.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/calendar/data/mail_data.xml | 13 | ||||
| -rw-r--r-- | addons/calendar/models/calendar.py | 12 |
2 files changed, 16 insertions, 9 deletions
diff --git a/addons/calendar/data/mail_data.xml b/addons/calendar/data/mail_data.xml index 6ca27e26c5b..21d229b2bce 100644 --- a/addons/calendar/data/mail_data.xml +++ b/addons/calendar/data/mail_data.xml @@ -182,6 +182,11 @@ <field name="body_html" type="html"> <div> % set colors = {'needsAction': 'grey', 'accepted': 'green', 'tentative': '#FFFF00', 'declined': 'red'} + <!-- + In a recurring event case, the object.event_id is always the first event + This makes the event date (and a lot of other information) incorrect + --> + % set event_id = ctx.get('force_event_id') or object.event_id <p> Hello ${object.common_name},<br/><br/> This is a reminder for the below event : @@ -200,16 +205,16 @@ <table border="0" cellpadding="0" cellspacing="0"><tr> <td width="130px;"> <div style="border-top-left-radius: 3px; border-top-right-radius: 3px; font-size: 12px; border-collapse: separate; text-align: center; font-weight: bold; color: #ffffff; min-height: 18px; background-color: #875A7B; border: 1px solid #875A7B;"> - ${object.event_id.get_interval('dayname', tz=object.partner_id.tz if not object.event_id.allday else None)} + ${event_id.get_interval('dayname', tz=object.partner_id.tz if not event_id.allday else None)} </div> <div style="font-size: 48px; min-height: auto; font-weight: bold; text-align: center; color: #5F5F5F; background-color: #F8F8F8; border: 1px solid #875A7B;"> - ${object.event_id.get_interval('day', tz=object.partner_id.tz if not object.event_id.allday else None)} + ${event_id.get_interval('day', tz=object.partner_id.tz if not event_id.allday else None)} </div> <div style='font-size: 12px; text-align: center; font-weight: bold; color: #ffffff; background-color: #875A7B;'> - ${object.event_id.get_interval('month', tz=object.partner_id.tz if not object.event_id.allday else None)} + ${event_id.get_interval('month', tz=object.partner_id.tz if not event_id.allday else None)} </div> <div style="border-collapse: separate; color: #5F5F5F; text-align: center; font-size: 12px; border-bottom-right-radius: 3px; font-weight: bold; border: 1px solid #875A7B; border-bottom-left-radius: 3px;"> - ${not object.event_id.allday and object.event_id.get_interval('time', tz=object.partner_id.tz) or ''} + ${not event_id.allday and event_id.get_interval('time', tz=object.partner_id.tz) or ''} </div> </td> <td width="20px;"/> diff --git a/addons/calendar/models/calendar.py b/addons/calendar/models/calendar.py index 597bf760b95..f5cf378d400 100644 --- a/addons/calendar/models/calendar.py +++ b/addons/calendar/models/calendar.py @@ -159,7 +159,7 @@ class Attendee(models.Model): def copy(self, default=None): raise UserError(_('You cannot duplicate a calendar attendee.')) - def _send_mail_to_attendees(self, template_xmlid, force_send=False): + def _send_mail_to_attendees(self, template_xmlid, force_send=False, force_event_id=None): """ Send mail for event invitation to event attendees. :param template_xmlid: xml id of the email template to use to send the invitation :param force_send: if set to True, the mail(s) will be sent immediately (instead of the next queue processing) @@ -173,7 +173,7 @@ class Attendee(models.Model): invitation_template = self.env.ref(template_xmlid) # get ics file for all meetings - ics_files = self.mapped('event_id')._get_ics_file() + ics_files = force_event_id._get_ics_file() if force_event_id else self.mapped('event_id')._get_ics_file() # prepare rendering context for mail template colors = { @@ -187,7 +187,8 @@ class Attendee(models.Model): 'color': colors, 'action_id': self.env['ir.actions.act_window'].search([('view_id', '=', calendar_view.id)], limit=1).id, 'dbname': self._cr.dbname, - 'base_url': self.env['ir.config_parameter'].sudo().get_param('web.base.url', default='http://localhost:8069') + 'base_url': self.env['ir.config_parameter'].sudo().get_param('web.base.url', default='http://localhost:8069'), + 'force_event_id': force_event_id, }) invitation_template = invitation_template.with_context(rendering_context) @@ -196,7 +197,8 @@ class Attendee(models.Model): for attendee in self: if attendee.email or attendee.partner_id.email: # FIXME: is ics_file text or bytes? - ics_file = ics_files.get(attendee.event_id.id) + event_id = force_event_id.id if force_event_id else attendee.event_id.id + ics_file = ics_files.get(event_id) email_values = { 'model': None, # We don't want to have the mail in the tchatter while in queue! @@ -440,7 +442,7 @@ class AlarmManager(models.AbstractModel): result = False if alarm.alarm_type == 'email': - result = meeting.attendee_ids.filtered(lambda r: r.state != 'declined')._send_mail_to_attendees('calendar.calendar_template_meeting_reminder', force_send=True) + result = meeting.attendee_ids.filtered(lambda r: r.state != 'declined')._send_mail_to_attendees('calendar.calendar_template_meeting_reminder', force_send=True, force_event_id=meeting) return result def do_notif_reminder(self, alert): |
