diff --git a/mail_partner_opt_out/__manifest__.py b/mail_partner_opt_out/__manifest__.py index e264320..436be45 100644 --- a/mail_partner_opt_out/__manifest__.py +++ b/mail_partner_opt_out/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Mail Partner Opt Out", "summary": "Add the partner's email to the blackmailed list", - "version": "13.0.1.0.0", + "version": "14.0.1.0.0", "development_status": "Beta", "category": "Social Network", "website": "https://github.com/OCA/social", diff --git a/mail_partner_opt_out/models/__init__.py b/mail_partner_opt_out/models/__init__.py index 91fed54..3262073 100644 --- a/mail_partner_opt_out/models/__init__.py +++ b/mail_partner_opt_out/models/__init__.py @@ -1 +1 @@ -from . import res_partner +from . import mail_thread_blacklist diff --git a/mail_partner_opt_out/models/mail_thread_blacklist.py b/mail_partner_opt_out/models/mail_thread_blacklist.py new file mode 100644 index 0000000..736a1e0 --- /dev/null +++ b/mail_partner_opt_out/models/mail_thread_blacklist.py @@ -0,0 +1,10 @@ +from odoo import models + + +class MailBlackListMixin(models.AbstractModel): + _inherit = "mail.thread.blacklist" + + def mail_blacklist_add(self): + for rec in self: + if not rec.is_blacklisted and rec.email: + self.env["mail.blacklist"].sudo()._add(self.email) diff --git a/mail_partner_opt_out/models/res_partner.py b/mail_partner_opt_out/models/res_partner.py deleted file mode 100644 index 1dcb243..0000000 --- a/mail_partner_opt_out/models/res_partner.py +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2021 ForgeFlow S.L. -# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). -from odoo import _, fields, models - - -class ResPartner(models.Model): - _inherit = "res.partner" - - opt_out = fields.Boolean( - string="Opt Out", - compute="_compute_opt_out", - inverse="_inverse_opt_out", - search="_search_opt_out", - help="Setting this checkbox will add the partner's email to a " - "blacklist so that this email won't be considered in mailings.", - ) - - def _compute_opt_out(self): - blacklist = ( - self.env["mail.blacklist"] - .sudo() - .search([("email", "in", self.mapped("email"))]) - ) - blacklisted_emails = blacklist.mapped("email") - for rec in self: - if rec.email in blacklisted_emails: - rec.opt_out = True - else: - rec.opt_out = False - - def _inverse_opt_out(self): - for rec in self: - if rec.opt_out and rec.email: - self.env["mail.blacklist"].sudo()._add(self.email) - elif not rec.opt_out and rec.email: - self.env["mail.blacklist"].sudo()._remove(self.email) - - def _is_unsupported_search_operator(self, operator): - return operator not in ["=", "!="] - - def _search_opt_out(self, operator, value): - if self._is_unsupported_search_operator(operator): - raise ValueError(_("Unsupported search operator")) - blacklisted_emails = ( - self.env["mail.blacklist"].sudo().search([]).mapped("email") - ) - if (operator == "=" and value) or (operator == "!=" and not value): - search_operator = "in" - else: - search_operator = "not in" - return [("email", search_operator, blacklisted_emails)] diff --git a/mail_partner_opt_out/readme/DESCRIPTION.rst b/mail_partner_opt_out/readme/DESCRIPTION.rst index e01da34..175a015 100644 --- a/mail_partner_opt_out/readme/DESCRIPTION.rst +++ b/mail_partner_opt_out/readme/DESCRIPTION.rst @@ -1,3 +1,3 @@ This module adds the capability for a user to add a partner's email address to the blackmail list so that she will not receive any emails from mass -mailing campaigns. +mailing campaigns diff --git a/mail_partner_opt_out/readme/USAGE.rst b/mail_partner_opt_out/readme/USAGE.rst index eb1cca8..f576e53 100644 --- a/mail_partner_opt_out/readme/USAGE.rst +++ b/mail_partner_opt_out/readme/USAGE.rst @@ -1,6 +1,7 @@ -Go to a partner. Next to the partner's email address you will see the -checkbox 'Opt Out'. Once you press it the partner's email address will be -blacklisted and the checkbox will be set. If you uncheck if the email address +Go to a partner. Next to the partner's email address you will see +a plus symbol. Once you press it the partner's email address will be +blacklisted and then a ban will appear. If you click that ban the email address will be removed from the blacklist. -You can also search for partners using the opt out as search criteria. +You can also filter for the Blacklist attribute, to see all the partner's that +their email has been added to the blacklist. diff --git a/mail_partner_opt_out/views/res_partner_views.xml b/mail_partner_opt_out/views/res_partner_views.xml index 8d91b08..3874630 100644 --- a/mail_partner_opt_out/views/res_partner_views.xml +++ b/mail_partner_opt_out/views/res_partner_views.xml @@ -1,11 +1,19 @@ - + + res.partner.view.form.inherit.mail res.partner - +