[REF] mail, mass_mailing: stop using context for seen/optout list

Purpose of this commit is to keep blacklist and optout lists computation
at mailing level and correctly call it in composer. This allow to have
a clearer and more readable code as well as more robust.

Currently it is done by adding this information in context before invoking
the mail composer. It is now correctly done in composer: if a mailing is
linked to the composer, it calls both blacklist and optout lists methods.

LINKS

Task ID-2377974
Community PR odoo/odoo#61467
This commit is contained in:
Thibault Delavallée
2021-08-18 13:38:17 +00:00
parent 19ce266dbf
commit 4e709ca3b7
3 changed files with 15 additions and 6 deletions
+2 -4
View File
@@ -504,12 +504,10 @@ class MailComposer(models.TransientModel):
return blacklisted_rec_ids
def _get_done_emails(self, mail_values_dict):
seen_list = self._context.get('mass_mailing_seen_list') or []
return seen_list
return []
def _get_optout_emails(self, mail_values_dict):
opt_out_list = self._context.get('mass_mailing_opt_out_list') or []
return opt_out_list
return []
def _onchange_template_id(self, template_id, composition_mode, model, res_id):
""" - mass_mailing: we cannot render, so return the template values
-2
View File
@@ -603,8 +603,6 @@ class MassMailing(models.Model):
def _get_mass_mailing_context(self):
"""Returns extra context items with pre-filled blacklist and seen list for massmailing"""
return {
'mass_mailing_opt_out_list': self._get_opt_out_list(),
'mass_mailing_seen_list': self._get_seen_list(),
'post_convert_links': self._get_link_tracker_values(),
}
@@ -38,6 +38,7 @@ class MailComposeMessage(models.TransientModel):
'mailing_domain': self.active_domain,
'attachment_ids': [(6, 0, self.attachment_ids.ids)],
})
self.mass_mailing_id = mass_mailing.id
recipients_info = self._process_recipient_values(res)
mass_mail_layout = self.env.ref('mass_mailing.mass_mailing_mail_layout', raise_if_not_found=False)
@@ -69,3 +70,15 @@ class MailComposeMessage(models.TransientModel):
'auto_delete': not mass_mailing.keep_archives,
})
return res
def _get_done_emails(self, mail_values_dict):
seen_list = super(MailComposeMessage, self)._get_done_emails(mail_values_dict)
if self.mass_mailing_id:
seen_list += self.mass_mailing_id._get_seen_list()
return seen_list
def _get_optout_emails(self, mail_values_dict):
opt_out_list = super(MailComposeMessage, self)._get_optout_emails(mail_values_dict)
if self.mass_mailing_id:
opt_out_list += self.mass_mailing_id._get_opt_out_list()
return opt_out_list