2019-04-06 01:39:55 +02:00
|
|
|
# Copyright 2019 Tecnativa - Ernesto Tejeda
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
|
|
|
from odoo import models
|
|
|
|
|
|
|
|
|
|
|
|
class MailBlackList(models.Model):
|
2020-08-24 10:36:19 +02:00
|
|
|
_inherit = "mail.blacklist"
|
2019-04-06 01:39:55 +02:00
|
|
|
|
|
|
|
def _add(self, email):
|
2020-08-24 10:36:19 +02:00
|
|
|
mailing_id = self.env.context.get("mailing_id")
|
|
|
|
res_id = self.env.context.get("unsubscription_res_id")
|
2019-04-06 01:39:55 +02:00
|
|
|
if mailing_id and res_id:
|
2020-08-24 10:36:19 +02:00
|
|
|
mailing = self.env["mail.mass_mailing"].browse(mailing_id, self._prefetch)
|
2019-04-06 01:39:55 +02:00
|
|
|
model_name = mailing.mailing_model_real
|
2020-08-24 10:36:19 +02:00
|
|
|
self.env["mail.unsubscription"].create(
|
|
|
|
{
|
|
|
|
"email": email,
|
|
|
|
"mass_mailing_id": mailing_id,
|
|
|
|
"unsubscriber_id": "%s,%d" % (model_name, res_id),
|
|
|
|
"action": "blacklist_add",
|
|
|
|
}
|
|
|
|
)
|
2019-04-06 01:39:55 +02:00
|
|
|
return super()._add(email)
|
|
|
|
|
|
|
|
def _remove(self, email):
|
2020-08-24 10:36:19 +02:00
|
|
|
mailing_id = self.env.context.get("mailing_id")
|
|
|
|
res_id = self.env.context.get("unsubscription_res_id")
|
2019-04-06 01:39:55 +02:00
|
|
|
if mailing_id and res_id:
|
2020-08-24 10:36:19 +02:00
|
|
|
mailing = self.env["mail.mass_mailing"].browse(mailing_id, self._prefetch)
|
2019-04-06 01:39:55 +02:00
|
|
|
model_name = mailing.mailing_model_real
|
2020-08-24 10:36:19 +02:00
|
|
|
self.env["mail.unsubscription"].create(
|
|
|
|
{
|
|
|
|
"email": email,
|
|
|
|
"mass_mailing_id": mailing_id,
|
|
|
|
"unsubscriber_id": "%s,%d" % (model_name, res_id),
|
|
|
|
"action": "blacklist_rm",
|
|
|
|
}
|
|
|
|
)
|
2019-04-06 01:39:55 +02:00
|
|
|
return super()._remove(email)
|