[14.0][MIG]mail_partner_opt_out: Migration to 14.0
This commit is contained in:
parent
54620724cf
commit
6d43cd0cf5
@ -3,7 +3,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Mail Partner Opt Out",
|
"name": "Mail Partner Opt Out",
|
||||||
"summary": "Add the partner's email to the blackmailed list",
|
"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",
|
"development_status": "Beta",
|
||||||
"category": "Social Network",
|
"category": "Social Network",
|
||||||
"website": "https://github.com/OCA/social",
|
"website": "https://github.com/OCA/social",
|
||||||
|
@ -1 +1 @@
|
|||||||
from . import res_partner
|
from . import mail_thread_blacklist
|
||||||
|
10
mail_partner_opt_out/models/mail_thread_blacklist.py
Normal file
10
mail_partner_opt_out/models/mail_thread_blacklist.py
Normal file
@ -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)
|
@ -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)]
|
|
@ -1,3 +1,3 @@
|
|||||||
This module adds the capability for a user to add a partner's email address
|
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
|
to the blackmail list so that she will not receive any emails from mass
|
||||||
mailing campaigns.
|
mailing campaigns
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
Go to a partner. Next to the partner's email address you will see the
|
Go to a partner. Next to the partner's email address you will see
|
||||||
checkbox 'Opt Out'. Once you press it the partner's email address will be
|
a plus symbol. 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
|
blacklisted and then a ban will appear. If you click that ban the email address
|
||||||
will be removed from the blacklist.
|
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.
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<record id="view_partner_form" model="ir.ui.view">
|
<record id="res_partner_view_form_inherit_mail" model="ir.ui.view">
|
||||||
|
<field name="name">res.partner.view.form.inherit.mail</field>
|
||||||
<field name="model">res.partner</field>
|
<field name="model">res.partner</field>
|
||||||
<field name="inherit_id" ref="base.view_partner_form" />
|
<field name="inherit_id" ref="base.view_partner_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="email" position="before">
|
<field name="email" position="before">
|
||||||
<field name="opt_out" string="Opt Out" />
|
<button
|
||||||
|
name="mail_blacklist_add"
|
||||||
|
class="fa fa-plus text-success"
|
||||||
|
title="Click to add this email to the blacklist."
|
||||||
|
type="object"
|
||||||
|
groups="base.group_user"
|
||||||
|
attrs="{'invisible': [('is_blacklisted', '=', True)]}"
|
||||||
|
/>
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user