diff --git a/addons/auth_signup/tests/test_reset_password.py b/addons/auth_signup/tests/test_reset_password.py index e345a647ae7..66168d5d2c8 100644 --- a/addons/auth_signup/tests/test_reset_password.py +++ b/addons/auth_signup/tests/test_reset_password.py @@ -18,7 +18,7 @@ class TestResetPassword(HttpCase): 'email': 'noop@example.com', }) - self.assertEqual(test_user.email, url_parse(test_user.signup_url).decode_query()["signup_email"], "query must contain 'signup_email'") + self.assertEqual(test_user.email, url_parse(test_user.with_context(create_user=True).signup_url).decode_query()["signup_email"], "query must contain 'signup_email'") # Invalidate signup_url to skip signup process self.env.invalidate_all() diff --git a/addons/hr_holidays_attendance/models/hr_leave.py b/addons/hr_holidays_attendance/models/hr_leave.py index 26c67d0aa20..80d43554ddf 100644 --- a/addons/hr_holidays_attendance/models/hr_leave.py +++ b/addons/hr_holidays_attendance/models/hr_leave.py @@ -56,7 +56,7 @@ class HRLeave(models.Model): if employee.user_id == self.env.user: raise ValidationError(_('You do not have enough extra hours to request this leave')) raise ValidationError(_('The employee does not have enough extra hours to request this leave.')) - if not leave.overtime_id: + if not leave.sudo().overtime_id: leave.sudo().overtime_id = self.env['hr.attendance.overtime'].sudo().create({ 'employee_id': employee.id, 'date': fields.Date.today(), diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index 5356e525ea4..ffcd806c6bb 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -84,6 +84,7 @@ class MailMail(models.Model): auto_delete = fields.Boolean( '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.") + # Unused since v16, to remove in master. to_delete = fields.Boolean('To Delete', help='If set, the mail will be deleted during the next Email Queue CRON run.') 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.") @@ -111,19 +112,6 @@ class MailMail(models.Model): restricted_attaments = mail_sudo.attachment_ids - IrAttachment._filter_attachment_access(mail_sudo.attachment_ids.ids) mail_sudo.attachment_ids = restricted_attaments | mail.unrestricted_attachment_ids - def init(self): - """Create a partial index on "to_delete" to make the search on those records fast. - - The benefit on this partial index is to not have a big impact on the - update / insert of other records in the database in comparison to a standard - index. - """ - self._cr.execute(""" - CREATE INDEX IF NOT EXISTS mail_mail_to_delete_idx - ON mail_mail(id) - WHERE to_delete = TRUE; - """) - @api.model_create_multi def create(self, values_list): # notification field: if not set, set if mail comes from an existing mail.message @@ -137,7 +125,7 @@ class MailMail(models.Model): values['scheduled_date'] = False # void string crashes new_mails = super(MailMail, self).create(values_list) - new_mails_w_attach = self + new_mails_w_attach = self.env['mail.mail'] for mail, values in zip(new_mails, values_list): if values.get('attachment_ids'): new_mails_w_attach += mail @@ -239,8 +227,6 @@ class MailMail(models.Model): except Exception: _logger.exception("Failed processing mail queue") - # Remove all the marked as "to delete" - self.env['mail.mail'].sudo().search([('to_delete', '=', True)]).unlink() return res def _postprocess_sent_message(self, success_pids, failure_reason=False, failure_type=None): @@ -278,7 +264,7 @@ class MailMail(models.Model): # TDE TODO: could be great to notify message-based, not notifications-based, to lessen number of notifs messages._notify_message_notification_update() # notify user that we have a failure if not failure_type or failure_type in ['mail_email_invalid', 'mail_email_missing']: # if we have another error, we want to keep the mail. - self.filtered(lambda mail: mail.auto_delete).to_delete = True + self.filtered(lambda mail: mail.auto_delete).unlink() return True diff --git a/addons/mail/tests/common.py b/addons/mail/tests/common.py index 4605d50513b..905d09feccf 100644 --- a/addons/mail/tests/common.py +++ b/addons/mail/tests/common.py @@ -77,11 +77,6 @@ class MockEmail(common.BaseCase, MockSmtplibCase): self.mail_mail_create_mocked = mail_mail_create_mocked yield - if mail_unlink_sent: - # Remove all the marked as to_delete to simulate the CRON - # Make tests easier and keep backward compatibility before this patch - self.env['mail.mail'].sudo().search([('to_delete', '=', True)]).unlink() - def _init_mail_mock(self): self._mails = [] self._mails_args = [] diff --git a/addons/mail/views/mail_mail_views.xml b/addons/mail/views/mail_mail_views.xml index af7ae67a357..16270994f6d 100644 --- a/addons/mail/views/mail_mail_views.xml +++ b/addons/mail/views/mail_mail_views.xml @@ -46,8 +46,7 @@ - + @@ -99,7 +98,7 @@ - +