diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index afef9897340..02f8edbb129 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -85,7 +85,7 @@ class MailMail(models.Model): 'Auto Delete', help="This option permanently removes any track of email after it's been sent, including from the Technical menu in the Settings, in order to preserve storage space of your Odoo database.") to_delete = fields.Boolean('To Delete', help='If set, the mail will be deleted during the next Email Queue CRON run.') - scheduled_date = fields.Char('Scheduled Send Date', + scheduled_date = fields.Datetime('Scheduled Send Date', help="If set, the queue manager will send the email after the date. If not set, the email will be send as soon as possible. Unless a timezone is specified, it is considered as being in UTC timezone.") fetchmail_server_id = fields.Many2one('fetchmail.server', "Inbound Mail Server", readonly=True) @@ -132,10 +132,9 @@ class MailMail(models.Model): values['is_notification'] = True if values.get('scheduled_date'): parsed_datetime = self._parse_scheduled_datetime(values['scheduled_date']) - if parsed_datetime: - values['scheduled_date'] = parsed_datetime.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) - else: - values['scheduled_date'] = False + values['scheduled_date'] = parsed_datetime.replace(tzinfo=None) if parsed_datetime else False + else: + values['scheduled_date'] = False # void string crashes new_mails = super(MailMail, self).create(values_list) new_mails_w_attach = self @@ -150,10 +149,7 @@ class MailMail(models.Model): def write(self, vals): if vals.get('scheduled_date'): parsed_datetime = self._parse_scheduled_datetime(vals['scheduled_date']) - if parsed_datetime: - vals['scheduled_date'] = parsed_datetime.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) - else: - vals['scheduled_date'] = False + vals['scheduled_date'] = parsed_datetime.replace(tzinfo=None) if parsed_datetime else False res = super(MailMail, self).write(vals) if vals.get('attachment_ids'): for mail in self: diff --git a/addons/mail/models/mail_template.py b/addons/mail/models/mail_template.py index 0040412c4e2..e149c1271f3 100644 --- a/addons/mail/models/mail_template.py +++ b/addons/mail/models/mail_template.py @@ -4,7 +4,6 @@ import base64 import logging - from odoo import _, api, fields, models, tools, Command from odoo.exceptions import UserError from odoo.tools import is_html_empty diff --git a/addons/test_mail/tests/test_mail_mail.py b/addons/test_mail/tests/test_mail_mail.py index 646cbf86945..76d9ca4fcd2 100644 --- a/addons/test_mail/tests/test_mail_mail.py +++ b/addons/test_mail/tests/test_mail_mail.py @@ -231,7 +231,7 @@ class TestMailMail(TestMailCommon): (now + timedelta(hours=-3)).strftime("%H:%M:%S %d-%m-%Y") + " -0400", ] expected_datetimes = [ - False, '', False, + False, False, False, now, now - pytz.timezone('Australia/Brisbane').utcoffset(now), now - timedelta(days=1), now + timedelta(days=1), now + timedelta(days=1), now + timedelta(hours=-1), @@ -253,9 +253,8 @@ class TestMailMail(TestMailCommon): ]) for mail, expected_datetime, scheduled_datetime in zip(mails, expected_datetimes, scheduled_datetimes): - expected = expected_datetime.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) if expected_datetime else expected_datetime - self.assertEqual(mail.scheduled_date, expected, - 'Scheduled date: %s should be stored as %s, received %s' % (scheduled_datetime, expected, mail.scheduled_date)) + self.assertEqual(mail.scheduled_date, expected_datetime, + 'Scheduled date: %s should be stored as %s, received %s' % (scheduled_datetime, expected_datetime, mail.scheduled_date)) self.assertEqual(mail.state, 'outgoing') with freeze_time(now):