[MIG]Mass Mailing Unique and Partner to v15
This commit is contained in:
parent
e025b64586
commit
19f2101b5d
109
mass_mailing_partner/README.rst
Normal file
109
mass_mailing_partner/README.rst
Normal file
@ -0,0 +1,109 @@
|
||||
===============================
|
||||
Link partners with mass-mailing
|
||||
===============================
|
||||
|
||||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
|
||||
:target: https://odoo-community.org/page/development-status
|
||||
:alt: Beta
|
||||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
|
||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
|
||||
:target: https://github.com/OCA/social/tree/14.0/mass_mailing_partner
|
||||
:alt: OCA/social
|
||||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||
:target: https://translation.odoo-community.org/projects/social-14-0/social-14-0-mass_mailing_partner
|
||||
:alt: Translate me on Weblate
|
||||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||
:target: https://runbot.odoo-community.org/runbot/205/14.0
|
||||
:alt: Try me on Runbot
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|
||||
This module links mass-mailing contacts with partners.
|
||||
|
||||
Features
|
||||
~~~~~~~~
|
||||
|
||||
* When creating or saving a mass-mailing contact, partners are matched through
|
||||
email, linking matched partner, or creating a new one if no match and the
|
||||
maling list partner mandatory field is checked.
|
||||
* Mailing contacts smart button in partner form.
|
||||
* Mass mailing stats smart button in partner form.
|
||||
* Filter and group by partner in mail statistics tree view
|
||||
|
||||
**Table of contents**
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
At first install, all existing mass mailing contacts are matched against
|
||||
partners. And also mass mailing statistics are matched using model and res_id.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
In partner view, there is a new action called "Add to mailing list". This
|
||||
action open a pop-up to select a mailing list. Selected partners will be added
|
||||
as mailing list contacts.
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mass_mailing_partner%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
|
||||
Do not contact contributors directly about support or help with technical issues.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Authors
|
||||
~~~~~~~
|
||||
|
||||
* Tecnativa
|
||||
|
||||
Contributors
|
||||
~~~~~~~~~~~~
|
||||
|
||||
* `Tecnativa <https://www.tecnativa.com>`_:
|
||||
|
||||
* Pedro M. Baeza
|
||||
* Rafael Blasco
|
||||
* Antonio Espinosa
|
||||
* Javier Iniesta
|
||||
* Jairo Llopis
|
||||
* David Vidal
|
||||
* Ernesto Tejeda
|
||||
* Victor M.M. Torres
|
||||
* Manuel Calero
|
||||
* Víctor Martínez
|
||||
|
||||
* `Hibou Corp. <https://hibou.io>`_
|
||||
|
||||
Maintainers
|
||||
~~~~~~~~~~~
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
.. image:: https://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: https://odoo-community.org
|
||||
|
||||
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
This module is part of the `OCA/social <https://github.com/OCA/social/tree/14.0/mass_mailing_partner>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
5
mass_mailing_partner/__init__.py
Normal file
5
mass_mailing_partner/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import models
|
||||
from . import wizard
|
||||
from .hooks import post_init_hook
|
25
mass_mailing_partner/__manifest__.py
Normal file
25
mass_mailing_partner/__manifest__.py
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2015-2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
"name": "Link partners with mass-mailing",
|
||||
"version": "14.0.1.1.0",
|
||||
"author": "Tecnativa, " "Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/social",
|
||||
"license": "AGPL-3",
|
||||
"category": "Marketing",
|
||||
"depends": ["mass_mailing"],
|
||||
"post_init_hook": "post_init_hook",
|
||||
"data": [
|
||||
"security/ir.model.access.csv",
|
||||
"views/mailing_trace_view.xml",
|
||||
"views/mailing_contact_view.xml",
|
||||
"views/mailing_view.xml",
|
||||
"views/res_partner_view.xml",
|
||||
"wizard/partner_mail_list_wizard.xml",
|
||||
],
|
||||
"installable": True,
|
||||
}
|
33
mass_mailing_partner/hooks.py
Normal file
33
mass_mailing_partner/hooks.py
Normal file
@ -0,0 +1,33 @@
|
||||
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
# Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import SUPERUSER_ID, api
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def post_init_hook(cr, registry):
|
||||
with api.Environment.manage():
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
# ACTION 1: Match existing contacts
|
||||
contact_model = env["mailing.contact"]
|
||||
partner_model = env["res.partner"]
|
||||
contacts = contact_model.search([("email", "!=", False)])
|
||||
_logger.info("Trying to match %d contacts to partner by email", len(contacts))
|
||||
for contact in contacts:
|
||||
partners = partner_model.search(
|
||||
[("email", "=ilike", contact.email)], limit=1
|
||||
)
|
||||
if partners:
|
||||
contact.write({"partner_id": partners.id})
|
||||
# ACTION 2: Match existing statistics
|
||||
stat_model = env["mailing.trace"]
|
||||
stats = stat_model.search([("model", "!=", False), ("res_id", "!=", False)])
|
||||
_logger.info("Trying to link %d mass mailing statistics to partner", len(stats))
|
||||
stats.partner_link()
|
7
mass_mailing_partner/models/__init__.py
Normal file
7
mass_mailing_partner/models/__init__.py
Normal file
@ -0,0 +1,7 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import mailing_contact
|
||||
from . import mailing_list
|
||||
from . import mailing_trace
|
||||
from . import mailing_contact_subscription
|
||||
from . import res_partner
|
107
mass_mailing_partner/models/mailing_contact.py
Normal file
107
mass_mailing_partner/models/mailing_contact.py
Normal file
@ -0,0 +1,107 @@
|
||||
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
# Copyright 2017 David Vidal <david.vidal@tecnativa.com>
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# Copyright 2020 Hibou Corp.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class MailingContact(models.Model):
|
||||
_inherit = "mailing.contact"
|
||||
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name="res.partner", string="Partner", domain=[("email", "!=", False)]
|
||||
)
|
||||
|
||||
@api.constrains("partner_id", "list_ids")
|
||||
def _check_partner_id_list_ids(self):
|
||||
for contact in self:
|
||||
if contact.partner_id:
|
||||
other_contact = self.search(
|
||||
[
|
||||
("partner_id", "=", contact.partner_id.id),
|
||||
("id", "!=", contact.id),
|
||||
]
|
||||
)
|
||||
if contact.list_ids & other_contact.mapped("list_ids"):
|
||||
raise ValidationError(
|
||||
_("Partner already exists in one of these mailing lists")
|
||||
+ ": %s" % contact.partner_id.display_name
|
||||
)
|
||||
|
||||
@api.onchange("partner_id")
|
||||
def _onchange_partner_mass_mailing_partner(self):
|
||||
if self.partner_id:
|
||||
self.name = self.partner_id.name
|
||||
self.email = self.partner_id.email
|
||||
self.title_id = self.partner_id.title
|
||||
self.company_name = self.partner_id.company_id.name
|
||||
self.country_id = self.partner_id.country_id
|
||||
category_ids = self.partner_id.category_id
|
||||
if category_ids:
|
||||
self.tag_ids = category_ids
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
record = self.new(vals)
|
||||
if not record.partner_id:
|
||||
record._set_partner()
|
||||
record._onchange_partner_mass_mailing_partner()
|
||||
new_vals = record._convert_to_write(record._cache)
|
||||
new_vals.update(
|
||||
subscription_list_ids=vals.get("subscription_list_ids", []),
|
||||
list_ids=vals.get("list_ids", []),
|
||||
)
|
||||
return super().create(new_vals)
|
||||
|
||||
def write(self, vals):
|
||||
for contact in self:
|
||||
new_vals = contact.copy_data(vals)[0]
|
||||
record = self.new(new_vals)
|
||||
if not record.partner_id:
|
||||
record._set_partner()
|
||||
record._onchange_partner_mass_mailing_partner()
|
||||
new_vals = record._convert_to_write(record._cache)
|
||||
new_vals.update(
|
||||
subscription_list_ids=vals.get("subscription_list_ids", []),
|
||||
list_ids=vals.get("list_ids", []),
|
||||
)
|
||||
super(MailingContact, contact).write(new_vals)
|
||||
return True
|
||||
|
||||
def _get_categories(self):
|
||||
ca_ids = self.tag_ids.ids + self.list_ids.mapped("partner_category.id")
|
||||
return [[6, 0, ca_ids]]
|
||||
|
||||
def _prepare_partner(self):
|
||||
return {
|
||||
"name": self.name or self.email,
|
||||
"email": self.email,
|
||||
"country_id": self.country_id.id,
|
||||
"title": self.title_id.id,
|
||||
"company_name": self.company_name,
|
||||
"company_id": False,
|
||||
"category_id": self._get_categories(),
|
||||
}
|
||||
|
||||
def _set_partner(self):
|
||||
self.ensure_one()
|
||||
if not self.email:
|
||||
return
|
||||
m_partner = self.env["res.partner"]
|
||||
# Look for a partner with that email
|
||||
email = self.email.strip()
|
||||
partner = m_partner.search([("email", "=ilike", email)], limit=1)
|
||||
if partner:
|
||||
# Partner found
|
||||
self.partner_id = partner
|
||||
else:
|
||||
lts = self.subscription_list_ids.mapped("list_id") | self.list_ids
|
||||
if lts.filtered("partner_mandatory"):
|
||||
# Create partner
|
||||
partner_vals = self._prepare_partner()
|
||||
self.partner_id = m_partner.sudo().create(partner_vals)
|
20
mass_mailing_partner/models/mailing_contact_subscription.py
Normal file
20
mass_mailing_partner/models/mailing_contact_subscription.py
Normal file
@ -0,0 +1,20 @@
|
||||
# Copyright 2018 Tecnativa - Ernesto Tejeda
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import _, api, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class MailingContactSubscription(models.Model):
|
||||
_inherit = "mailing.contact.subscription"
|
||||
|
||||
@api.constrains("contact_id", "list_id")
|
||||
def _check_contact_id_partner_id_list_id(self):
|
||||
for rel in self:
|
||||
if rel.contact_id.partner_id:
|
||||
contacts = rel.list_id.contact_ids - rel.contact_id
|
||||
if rel.contact_id.partner_id in contacts.mapped("partner_id"):
|
||||
raise ValidationError(
|
||||
_("A partner cannot be multiple times in the same list")
|
||||
)
|
34
mass_mailing_partner/models/mailing_list.py
Normal file
34
mass_mailing_partner/models/mailing_list.py
Normal file
@ -0,0 +1,34 @@
|
||||
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class MailingList(models.Model):
|
||||
_inherit = "mailing.list"
|
||||
|
||||
partner_mandatory = fields.Boolean(string="Mandatory Partner", default=False)
|
||||
partner_category = fields.Many2one(
|
||||
comodel_name="res.partner.category", string="Partner Tag"
|
||||
)
|
||||
|
||||
@api.constrains("contact_ids")
|
||||
def _check_contact_ids_partner_id(self):
|
||||
contact_obj = self.env["mailing.contact"]
|
||||
for mailing_list in self:
|
||||
data = contact_obj.read_group(
|
||||
[
|
||||
("id", "in", mailing_list.contact_ids.ids),
|
||||
("partner_id", "!=", False),
|
||||
],
|
||||
["partner_id"],
|
||||
["partner_id"],
|
||||
)
|
||||
if len(list(filter(lambda r: r["partner_id_count"] > 1, data))):
|
||||
raise ValidationError(
|
||||
_("A partner cannot be multiple times " "in the same list")
|
||||
)
|
37
mass_mailing_partner/models/mailing_trace.py
Normal file
37
mass_mailing_partner/models/mailing_trace.py
Normal file
@ -0,0 +1,37 @@
|
||||
# Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class MailingTrace(models.Model):
|
||||
_inherit = "mailing.trace"
|
||||
|
||||
partner_id = fields.Many2one(
|
||||
string="Partner", comodel_name="res.partner", readonly=True
|
||||
)
|
||||
|
||||
@api.model
|
||||
def partner_id_from_obj(self, model, res_id):
|
||||
partner_id = False
|
||||
obj = self.env[model].browse(res_id)
|
||||
if obj.exists():
|
||||
if model == "res.partner":
|
||||
partner_id = res_id
|
||||
elif "partner_id" in obj._fields:
|
||||
partner_id = obj.partner_id.id
|
||||
return partner_id
|
||||
|
||||
def partner_link(self):
|
||||
for stat in self.filtered(lambda r: r.model and r.res_id):
|
||||
partner_id = self.partner_id_from_obj(stat.model, stat.res_id)
|
||||
if partner_id != stat.partner_id.id:
|
||||
stat.partner_id = partner_id
|
||||
return True
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
stat = super().create(vals)
|
||||
stat.partner_link()
|
||||
return stat
|
94
mass_mailing_partner/models/res_partner.py
Normal file
94
mass_mailing_partner/models/res_partner.py
Normal file
@ -0,0 +1,94 @@
|
||||
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
# Copyright 2017 David Vidal <david.vidal@tecnativa.com>
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = "res.partner"
|
||||
|
||||
mass_mailing_contact_ids = fields.One2many(
|
||||
string="Mailing contacts",
|
||||
comodel_name="mailing.contact",
|
||||
inverse_name="partner_id",
|
||||
)
|
||||
mass_mailing_contacts_count = fields.Integer(
|
||||
string="Mailing contacts number",
|
||||
compute="_compute_mass_mailing_contacts_count",
|
||||
store=True,
|
||||
compute_sudo=True,
|
||||
)
|
||||
mass_mailing_stats_ids = fields.One2many(
|
||||
string="Mass mailing stats",
|
||||
comodel_name="mailing.trace",
|
||||
inverse_name="partner_id",
|
||||
)
|
||||
mass_mailing_stats_count = fields.Integer(
|
||||
string="Mass mailing stats number",
|
||||
compute="_compute_mass_mailing_stats_count",
|
||||
store=True,
|
||||
)
|
||||
|
||||
@api.constrains("email")
|
||||
def _check_email_mass_mailing_contacts(self):
|
||||
for partner in self:
|
||||
if not partner.email and partner.sudo().mass_mailing_contact_ids:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"This partner '%s' is linked to one or more mass "
|
||||
"mailing contact. Email must be assigned."
|
||||
)
|
||||
% partner.name
|
||||
)
|
||||
|
||||
@api.depends("mass_mailing_contact_ids")
|
||||
def _compute_mass_mailing_contacts_count(self):
|
||||
contact_data = self.env["mailing.contact"].read_group(
|
||||
[("partner_id", "in", self.ids)], ["partner_id"], ["partner_id"]
|
||||
)
|
||||
mapped_data = {
|
||||
contact["partner_id"][0]: contact["partner_id_count"]
|
||||
for contact in contact_data
|
||||
}
|
||||
for partner in self:
|
||||
partner.mass_mailing_contacts_count = mapped_data.get(partner.id, 0)
|
||||
|
||||
@api.depends("mass_mailing_stats_ids")
|
||||
def _compute_mass_mailing_stats_count(self):
|
||||
contact_data = self.env["mailing.trace"].read_group(
|
||||
[("partner_id", "in", self.ids)], ["partner_id"], ["partner_id"]
|
||||
)
|
||||
mapped_data = {
|
||||
contact["partner_id"][0]: contact["partner_id_count"]
|
||||
for contact in contact_data
|
||||
}
|
||||
for partner in self:
|
||||
partner.mass_mailing_stats_count = mapped_data.get(partner.id, 0)
|
||||
|
||||
def write(self, vals):
|
||||
res = super().write(vals)
|
||||
mm_vals = {}
|
||||
if vals.get("name"):
|
||||
mm_vals["name"] = vals["name"]
|
||||
if vals.get("email"):
|
||||
mm_vals["email"] = vals["email"]
|
||||
if vals.get("title"):
|
||||
mm_vals["title_id"] = vals["title"]
|
||||
if vals.get("parent_id"):
|
||||
parent = self.browse(vals.get("parent_id"))
|
||||
mm_vals["company_name"] = parent.commercial_company_name
|
||||
if vals.get("country_id"):
|
||||
mm_vals["country_id"] = vals["country_id"]
|
||||
if vals.get("category_id"):
|
||||
mm_vals["tag_ids"] = vals["category_id"]
|
||||
if mm_vals:
|
||||
# Using sudo because ACLs shouldn't produce data inconsistency
|
||||
self.env["mailing.contact"].sudo().search(
|
||||
[("partner_id", "in", self.ids)]
|
||||
).write(mm_vals)
|
||||
return res
|
2
mass_mailing_partner/readme/CONFIGURE.rst
Normal file
2
mass_mailing_partner/readme/CONFIGURE.rst
Normal file
@ -0,0 +1,2 @@
|
||||
At first install, all existing mass mailing contacts are matched against
|
||||
partners. And also mass mailing statistics are matched using model and res_id.
|
14
mass_mailing_partner/readme/CONTRIBUTORS.rst
Normal file
14
mass_mailing_partner/readme/CONTRIBUTORS.rst
Normal file
@ -0,0 +1,14 @@
|
||||
* `Tecnativa <https://www.tecnativa.com>`_:
|
||||
|
||||
* Pedro M. Baeza
|
||||
* Rafael Blasco
|
||||
* Antonio Espinosa
|
||||
* Javier Iniesta
|
||||
* Jairo Llopis
|
||||
* David Vidal
|
||||
* Ernesto Tejeda
|
||||
* Victor M.M. Torres
|
||||
* Manuel Calero
|
||||
* Víctor Martínez
|
||||
|
||||
* `Hibou Corp. <https://hibou.io>`_
|
11
mass_mailing_partner/readme/DESCRIPTION.rst
Normal file
11
mass_mailing_partner/readme/DESCRIPTION.rst
Normal file
@ -0,0 +1,11 @@
|
||||
This module links mass-mailing contacts with partners.
|
||||
|
||||
Features
|
||||
~~~~~~~~
|
||||
|
||||
* When creating or saving a mass-mailing contact, partners are matched through
|
||||
email, linking matched partner, or creating a new one if no match and the
|
||||
maling list partner mandatory field is checked.
|
||||
* Mailing contacts smart button in partner form.
|
||||
* Mass mailing stats smart button in partner form.
|
||||
* Filter and group by partner in mail statistics tree view
|
3
mass_mailing_partner/readme/USAGE.rst
Normal file
3
mass_mailing_partner/readme/USAGE.rst
Normal file
@ -0,0 +1,3 @@
|
||||
In partner view, there is a new action called "Add to mailing list". This
|
||||
action open a pop-up to select a mailing list. Selected partners will be added
|
||||
as mailing list contacts.
|
2
mass_mailing_partner/security/ir.model.access.csv
Normal file
2
mass_mailing_partner/security/ir.model.access.csv
Normal file
@ -0,0 +1,2 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_partner_mail_list_wizard,access_partner_mail_list_wizard,model_partner_mail_list_wizard,base.group_user,1,1,1,0
|
|
BIN
mass_mailing_partner/static/description/icon.png
Normal file
BIN
mass_mailing_partner/static/description/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
455
mass_mailing_partner/static/description/index.html
Normal file
455
mass_mailing_partner/static/description/index.html
Normal file
@ -0,0 +1,455 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
|
||||
<title>Link partners with mass-mailing</title>
|
||||
<style type="text/css">
|
||||
|
||||
/*
|
||||
:Author: David Goodger (goodger@python.org)
|
||||
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
|
||||
:Copyright: This stylesheet has been placed in the public domain.
|
||||
|
||||
Default cascading style sheet for the HTML output of Docutils.
|
||||
|
||||
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
|
||||
customize this style sheet.
|
||||
*/
|
||||
|
||||
/* used to remove borders from tables and images */
|
||||
.borderless, table.borderless td, table.borderless th {
|
||||
border: 0 }
|
||||
|
||||
table.borderless td, table.borderless th {
|
||||
/* Override padding for "table.docutils td" with "! important".
|
||||
The right padding separates the table cells. */
|
||||
padding: 0 0.5em 0 0 ! important }
|
||||
|
||||
.first {
|
||||
/* Override more specific margin styles with "! important". */
|
||||
margin-top: 0 ! important }
|
||||
|
||||
.last, .with-subtitle {
|
||||
margin-bottom: 0 ! important }
|
||||
|
||||
.hidden {
|
||||
display: none }
|
||||
|
||||
.subscript {
|
||||
vertical-align: sub;
|
||||
font-size: smaller }
|
||||
|
||||
.superscript {
|
||||
vertical-align: super;
|
||||
font-size: smaller }
|
||||
|
||||
a.toc-backref {
|
||||
text-decoration: none ;
|
||||
color: black }
|
||||
|
||||
blockquote.epigraph {
|
||||
margin: 2em 5em ; }
|
||||
|
||||
dl.docutils dd {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Uncomment (and remove this text!) to get bold-faced definition list terms
|
||||
dl.docutils dt {
|
||||
font-weight: bold }
|
||||
*/
|
||||
|
||||
div.abstract {
|
||||
margin: 2em 5em }
|
||||
|
||||
div.abstract p.topic-title {
|
||||
font-weight: bold ;
|
||||
text-align: center }
|
||||
|
||||
div.admonition, div.attention, div.caution, div.danger, div.error,
|
||||
div.hint, div.important, div.note, div.tip, div.warning {
|
||||
margin: 2em ;
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.admonition p.admonition-title, div.hint p.admonition-title,
|
||||
div.important p.admonition-title, div.note p.admonition-title,
|
||||
div.tip p.admonition-title {
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
div.attention p.admonition-title, div.caution p.admonition-title,
|
||||
div.danger p.admonition-title, div.error p.admonition-title,
|
||||
div.warning p.admonition-title, .code .error {
|
||||
color: red ;
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
/* Uncomment (and remove this text!) to get reduced vertical space in
|
||||
compound paragraphs.
|
||||
div.compound .compound-first, div.compound .compound-middle {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
div.compound .compound-last, div.compound .compound-middle {
|
||||
margin-top: 0.5em }
|
||||
*/
|
||||
|
||||
div.dedication {
|
||||
margin: 2em 5em ;
|
||||
text-align: center ;
|
||||
font-style: italic }
|
||||
|
||||
div.dedication p.topic-title {
|
||||
font-weight: bold ;
|
||||
font-style: normal }
|
||||
|
||||
div.figure {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
div.footer, div.header {
|
||||
clear: both;
|
||||
font-size: smaller }
|
||||
|
||||
div.line-block {
|
||||
display: block ;
|
||||
margin-top: 1em ;
|
||||
margin-bottom: 1em }
|
||||
|
||||
div.line-block div.line-block {
|
||||
margin-top: 0 ;
|
||||
margin-bottom: 0 ;
|
||||
margin-left: 1.5em }
|
||||
|
||||
div.sidebar {
|
||||
margin: 0 0 0.5em 1em ;
|
||||
border: medium outset ;
|
||||
padding: 1em ;
|
||||
background-color: #ffffee ;
|
||||
width: 40% ;
|
||||
float: right ;
|
||||
clear: right }
|
||||
|
||||
div.sidebar p.rubric {
|
||||
font-family: sans-serif ;
|
||||
font-size: medium }
|
||||
|
||||
div.system-messages {
|
||||
margin: 5em }
|
||||
|
||||
div.system-messages h1 {
|
||||
color: red }
|
||||
|
||||
div.system-message {
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.system-message p.system-message-title {
|
||||
color: red ;
|
||||
font-weight: bold }
|
||||
|
||||
div.topic {
|
||||
margin: 2em }
|
||||
|
||||
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
|
||||
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
|
||||
margin-top: 0.4em }
|
||||
|
||||
h1.title {
|
||||
text-align: center }
|
||||
|
||||
h2.subtitle {
|
||||
text-align: center }
|
||||
|
||||
hr.docutils {
|
||||
width: 75% }
|
||||
|
||||
img.align-left, .figure.align-left, object.align-left, table.align-left {
|
||||
clear: left ;
|
||||
float: left ;
|
||||
margin-right: 1em }
|
||||
|
||||
img.align-right, .figure.align-right, object.align-right, table.align-right {
|
||||
clear: right ;
|
||||
float: right ;
|
||||
margin-left: 1em }
|
||||
|
||||
img.align-center, .figure.align-center, object.align-center {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
table.align-center {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.align-left {
|
||||
text-align: left }
|
||||
|
||||
.align-center {
|
||||
clear: both ;
|
||||
text-align: center }
|
||||
|
||||
.align-right {
|
||||
text-align: right }
|
||||
|
||||
/* reset inner alignment in figures */
|
||||
div.align-right {
|
||||
text-align: inherit }
|
||||
|
||||
/* div.align-center * { */
|
||||
/* text-align: left } */
|
||||
|
||||
.align-top {
|
||||
vertical-align: top }
|
||||
|
||||
.align-middle {
|
||||
vertical-align: middle }
|
||||
|
||||
.align-bottom {
|
||||
vertical-align: bottom }
|
||||
|
||||
ol.simple, ul.simple {
|
||||
margin-bottom: 1em }
|
||||
|
||||
ol.arabic {
|
||||
list-style: decimal }
|
||||
|
||||
ol.loweralpha {
|
||||
list-style: lower-alpha }
|
||||
|
||||
ol.upperalpha {
|
||||
list-style: upper-alpha }
|
||||
|
||||
ol.lowerroman {
|
||||
list-style: lower-roman }
|
||||
|
||||
ol.upperroman {
|
||||
list-style: upper-roman }
|
||||
|
||||
p.attribution {
|
||||
text-align: right ;
|
||||
margin-left: 50% }
|
||||
|
||||
p.caption {
|
||||
font-style: italic }
|
||||
|
||||
p.credits {
|
||||
font-style: italic ;
|
||||
font-size: smaller }
|
||||
|
||||
p.label {
|
||||
white-space: nowrap }
|
||||
|
||||
p.rubric {
|
||||
font-weight: bold ;
|
||||
font-size: larger ;
|
||||
color: maroon ;
|
||||
text-align: center }
|
||||
|
||||
p.sidebar-title {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold ;
|
||||
font-size: larger }
|
||||
|
||||
p.sidebar-subtitle {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
p.topic-title {
|
||||
font-weight: bold }
|
||||
|
||||
pre.address {
|
||||
margin-bottom: 0 ;
|
||||
margin-top: 0 ;
|
||||
font: inherit }
|
||||
|
||||
pre.literal-block, pre.doctest-block, pre.math, pre.code {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
pre.code .ln { color: grey; } /* line numbers */
|
||||
pre.code, code { background-color: #eeeeee }
|
||||
pre.code .comment, code .comment { color: #5C6576 }
|
||||
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
|
||||
pre.code .literal.string, code .literal.string { color: #0C5404 }
|
||||
pre.code .name.builtin, code .name.builtin { color: #352B84 }
|
||||
pre.code .deleted, code .deleted { background-color: #DEB0A1}
|
||||
pre.code .inserted, code .inserted { background-color: #A3D289}
|
||||
|
||||
span.classifier {
|
||||
font-family: sans-serif ;
|
||||
font-style: oblique }
|
||||
|
||||
span.classifier-delimiter {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
span.interpreted {
|
||||
font-family: sans-serif }
|
||||
|
||||
span.option {
|
||||
white-space: nowrap }
|
||||
|
||||
span.pre {
|
||||
white-space: pre }
|
||||
|
||||
span.problematic {
|
||||
color: red }
|
||||
|
||||
span.section-subtitle {
|
||||
/* font-size relative to parent (h1..h6 element) */
|
||||
font-size: 80% }
|
||||
|
||||
table.citation {
|
||||
border-left: solid 1px gray;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docinfo {
|
||||
margin: 2em 4em }
|
||||
|
||||
table.docutils {
|
||||
margin-top: 0.5em ;
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
table.footnote {
|
||||
border-left: solid 1px black;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docutils td, table.docutils th,
|
||||
table.docinfo td, table.docinfo th {
|
||||
padding-left: 0.5em ;
|
||||
padding-right: 0.5em ;
|
||||
vertical-align: top }
|
||||
|
||||
table.docutils th.field-name, table.docinfo th.docinfo-name {
|
||||
font-weight: bold ;
|
||||
text-align: left ;
|
||||
white-space: nowrap ;
|
||||
padding-left: 0 }
|
||||
|
||||
/* "booktabs" style (no vertical lines) */
|
||||
table.docutils.booktabs {
|
||||
border: 0px;
|
||||
border-top: 2px solid;
|
||||
border-bottom: 2px solid;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
table.docutils.booktabs * {
|
||||
border: 0px;
|
||||
}
|
||||
table.docutils.booktabs th {
|
||||
border-bottom: thin solid;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
|
||||
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
|
||||
font-size: 100% }
|
||||
|
||||
ul.auto-toc {
|
||||
list-style-type: none }
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document" id="link-partners-with-mass-mailing">
|
||||
<h1 class="title">Link partners with mass-mailing</h1>
|
||||
|
||||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/social/tree/14.0/mass_mailing_partner"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/social-14-0/social-14-0-mass_mailing_partner"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/205/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||
<p>This module links mass-mailing contacts with partners.</p>
|
||||
<div class="section" id="features">
|
||||
<h1>Features</h1>
|
||||
<ul class="simple">
|
||||
<li>When creating or saving a mass-mailing contact, partners are matched through
|
||||
email, linking matched partner, or creating a new one if no match and the
|
||||
maling list partner mandatory field is checked.</li>
|
||||
<li>Mailing contacts smart button in partner form.</li>
|
||||
<li>Mass mailing stats smart button in partner form.</li>
|
||||
<li>Filter and group by partner in mail statistics tree view</li>
|
||||
</ul>
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
<ul class="simple">
|
||||
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
|
||||
<li><a class="reference internal" href="#usage" id="id2">Usage</a></li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id4">Credits</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="configuration">
|
||||
<h2><a class="toc-backref" href="#id1">Configuration</a></h2>
|
||||
<p>At first install, all existing mass mailing contacts are matched against
|
||||
partners. And also mass mailing statistics are matched using model and res_id.</p>
|
||||
</div>
|
||||
<div class="section" id="usage">
|
||||
<h2><a class="toc-backref" href="#id2">Usage</a></h2>
|
||||
<p>In partner view, there is a new action called “Add to mailing list”. This
|
||||
action open a pop-up to select a mailing list. Selected partners will be added
|
||||
as mailing list contacts.</p>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
<h2><a class="toc-backref" href="#id3">Bug Tracker</a></h2>
|
||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mass_mailing_partner%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||
</div>
|
||||
<div class="section" id="credits">
|
||||
<h2><a class="toc-backref" href="#id4">Credits</a></h2>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="authors">
|
||||
<h1>Authors</h1>
|
||||
<ul class="simple">
|
||||
<li>Tecnativa</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="contributors">
|
||||
<h1>Contributors</h1>
|
||||
<ul>
|
||||
<li><p class="first"><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:</p>
|
||||
<blockquote>
|
||||
<ul class="simple">
|
||||
<li>Pedro M. Baeza</li>
|
||||
<li>Rafael Blasco</li>
|
||||
<li>Antonio Espinosa</li>
|
||||
<li>Javier Iniesta</li>
|
||||
<li>Jairo Llopis</li>
|
||||
<li>David Vidal</li>
|
||||
<li>Ernesto Tejeda</li>
|
||||
<li>Victor M.M. Torres</li>
|
||||
<li>Manuel Calero</li>
|
||||
<li>Víctor Martínez</li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
</li>
|
||||
<li><p class="first"><a class="reference external" href="https://hibou.io">Hibou Corp.</a></p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
<h1>Maintainers</h1>
|
||||
<p>This module is maintained by the OCA.</p>
|
||||
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
|
||||
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.</p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/14.0/mass_mailing_partner">OCA/social</a> project on GitHub.</p>
|
||||
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
7
mass_mailing_partner/tests/__init__.py
Normal file
7
mass_mailing_partner/tests/__init__.py
Normal file
@ -0,0 +1,7 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import test_mail_mass_mailing_contact, test_res_partner
|
||||
from . import test_mail_mail_statistics
|
||||
from . import test_partner_mail_list_wizard
|
||||
from . import test_mail_mass_mailing_list
|
||||
from . import test_mail_mass_mailing_list_contact_rel
|
67
mass_mailing_partner/tests/base.py
Normal file
67
mass_mailing_partner/tests/base.py
Normal file
@ -0,0 +1,67 @@
|
||||
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class BaseCase(TransactionCase):
|
||||
def setUp(self):
|
||||
super(BaseCase, self).setUp()
|
||||
|
||||
self.main_company = self.env.ref("base.main_company")
|
||||
self.country_es = self.env.ref("base.es")
|
||||
self.category_0 = self.env.ref("base.res_partner_category_0")
|
||||
self.category_2 = self.env.ref("base.res_partner_category_2")
|
||||
self.title_mister = self.env.ref("base.res_partner_title_mister")
|
||||
self.partner = self.create_partner(
|
||||
{
|
||||
"name": "Partner test",
|
||||
"email": "partner@test.com",
|
||||
"title": self.title_mister.id,
|
||||
"company_id": self.main_company.id,
|
||||
"country_id": self.country_es.id,
|
||||
"category_id": [(6, 0, (self.category_0 | self.category_2).ids)],
|
||||
}
|
||||
)
|
||||
|
||||
self.category_3 = self.env.ref("base.res_partner_category_3")
|
||||
self.mailing_list = self.create_mailing_list({"name": "List test"})
|
||||
self.mailing_list2 = self.create_mailing_list(
|
||||
{
|
||||
"name": "List test 2",
|
||||
"partner_mandatory": True,
|
||||
"partner_category": self.category_3.id,
|
||||
}
|
||||
)
|
||||
|
||||
def create_partner(self, vals):
|
||||
m_partner = self.env["res.partner"]
|
||||
return m_partner.create(vals)
|
||||
|
||||
def create_mailing_contact(self, vals):
|
||||
m_mailing_contact = self.env["mailing.contact"]
|
||||
return m_mailing_contact.create(vals)
|
||||
|
||||
def create_mailing_list(self, vals):
|
||||
m_mailing_list = self.env["mailing.list"]
|
||||
return m_mailing_list.create(vals)
|
||||
|
||||
def check_mailing_contact_partner(self, mailing_contact):
|
||||
if mailing_contact.partner_id:
|
||||
self.assertEqual(mailing_contact.partner_id.email, mailing_contact.email)
|
||||
self.assertEqual(mailing_contact.partner_id.name, mailing_contact.name)
|
||||
self.assertEqual(mailing_contact.partner_id.title, mailing_contact.title_id)
|
||||
if mailing_contact.partner_id.company_id:
|
||||
self.assertEqual(
|
||||
mailing_contact.partner_id.company_id.name,
|
||||
mailing_contact.company_name,
|
||||
)
|
||||
self.assertEqual(
|
||||
mailing_contact.partner_id.country_id, mailing_contact.country_id
|
||||
)
|
||||
self.assertEqual(
|
||||
mailing_contact.partner_id.category_id, mailing_contact.tag_ids
|
||||
)
|
30
mass_mailing_partner/tests/test_mail_mail_statistics.py
Normal file
30
mass_mailing_partner/tests/test_mail_mail_statistics.py
Normal file
@ -0,0 +1,30 @@
|
||||
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import base
|
||||
|
||||
|
||||
class MailMailStatisticsCase(base.BaseCase):
|
||||
def test_link_partner(self):
|
||||
partner = self.create_partner({"name": "Test partner"})
|
||||
stat = self.env["mailing.trace"].create(
|
||||
{"model": "res.partner", "res_id": partner.id}
|
||||
)
|
||||
self.assertEqual(partner.id, stat.partner_id.id)
|
||||
|
||||
def test_link_mail_contact(self):
|
||||
partner = self.create_partner(
|
||||
{"name": "Test partner", "email": "test@domain.com"}
|
||||
)
|
||||
contact_vals = {
|
||||
"partner_id": partner.id,
|
||||
"list_ids": [[6, 0, [self.mailing_list.id]]],
|
||||
}
|
||||
contact = self.create_mailing_contact(contact_vals)
|
||||
stat = self.env["mailing.trace"].create(
|
||||
{"model": "mailing.contact", "res_id": contact.id}
|
||||
)
|
||||
self.assertEqual(partner.id, stat.partner_id.id)
|
142
mass_mailing_partner/tests/test_mail_mass_mailing_contact.py
Normal file
142
mass_mailing_partner/tests/test_mail_mass_mailing_contact.py
Normal file
@ -0,0 +1,142 @@
|
||||
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from ..hooks import post_init_hook
|
||||
from . import base
|
||||
|
||||
|
||||
class MailMassMailingContactCase(base.BaseCase):
|
||||
def test_match_existing_contacts(self):
|
||||
contact = self.create_mailing_contact(
|
||||
{"email": "partner@test.com", "list_ids": [(6, 0, self.mailing_list.ids)]}
|
||||
)
|
||||
post_init_hook(self.cr, self.registry)
|
||||
self.assertEqual(contact.partner_id.id, self.partner.id)
|
||||
self.check_mailing_contact_partner(contact)
|
||||
|
||||
def test_create_mass_mailing_contact(self):
|
||||
title_doctor = self.env.ref("base.res_partner_title_doctor")
|
||||
country_cu = self.env.ref("base.cu")
|
||||
category_8 = self.env.ref("base.res_partner_category_8")
|
||||
category_11 = self.env.ref("base.res_partner_category_11")
|
||||
contact_vals = {
|
||||
"name": "Partner test 2",
|
||||
"email": "partner2@test.com",
|
||||
"title_id": title_doctor.id,
|
||||
"company_name": "TestCompany",
|
||||
"country_id": country_cu.id,
|
||||
"tag_ids": [(6, 0, (category_8 | category_11).ids)],
|
||||
"list_ids": [(6, 0, (self.mailing_list | self.mailing_list2).ids)],
|
||||
}
|
||||
contact = self.create_mailing_contact(contact_vals)
|
||||
self.check_mailing_contact_partner(contact)
|
||||
with self.assertRaises(ValidationError):
|
||||
self.create_mailing_contact(
|
||||
{
|
||||
"email": "partner2@test.com",
|
||||
"list_ids": [[6, 0, [self.mailing_list2.id]]],
|
||||
}
|
||||
)
|
||||
|
||||
def test_create_mass_mailing_contact_with_subscription(self):
|
||||
title_doctor = self.env.ref("base.res_partner_title_doctor")
|
||||
country_cu = self.env.ref("base.cu")
|
||||
category_8 = self.env.ref("base.res_partner_category_8")
|
||||
category_11 = self.env.ref("base.res_partner_category_11")
|
||||
contact_vals = {
|
||||
"name": "Partner test 2",
|
||||
"email": "partner2@test.com",
|
||||
"title_id": title_doctor.id,
|
||||
"company_name": "TestCompany",
|
||||
"country_id": country_cu.id,
|
||||
"tag_ids": [(6, 0, (category_8 | category_11).ids)],
|
||||
"subscription_list_ids": [
|
||||
(0, 0, {"list_id": self.mailing_list.id}),
|
||||
(0, 0, {"list_id": self.mailing_list2.id}),
|
||||
],
|
||||
}
|
||||
contact = self.create_mailing_contact(contact_vals)
|
||||
self.check_mailing_contact_partner(contact)
|
||||
with self.assertRaises(ValidationError):
|
||||
self.create_mailing_contact(
|
||||
{
|
||||
"email": "partner2@test.com",
|
||||
"subscription_list_ids": [
|
||||
(0, 0, {"list_id": self.mailing_list2.id})
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
def test_write_mass_mailing_contact(self):
|
||||
contact = self.create_mailing_contact(
|
||||
{"email": "partner@test.com", "list_ids": [(6, 0, self.mailing_list.ids)]}
|
||||
)
|
||||
contact.write({"partner_id": False})
|
||||
self.check_mailing_contact_partner(contact)
|
||||
contact2 = self.create_mailing_contact(
|
||||
{
|
||||
"email": "partner2@test.com",
|
||||
"name": "Partner test 2",
|
||||
"list_ids": [(6, 0, self.mailing_list.ids)],
|
||||
}
|
||||
)
|
||||
contact2.write({"partner_id": False})
|
||||
self.assertFalse(contact2.partner_id)
|
||||
|
||||
def test_onchange_partner(self):
|
||||
contact = self.create_mailing_contact(
|
||||
{"email": "partner@test.com", "list_ids": [[6, 0, [self.mailing_list.id]]]}
|
||||
)
|
||||
title_doctor = self.env.ref("base.res_partner_title_doctor")
|
||||
country_cu = self.env.ref("base.cu")
|
||||
category_8 = self.env.ref("base.res_partner_category_8")
|
||||
category_11 = self.env.ref("base.res_partner_category_11")
|
||||
partner_vals = {
|
||||
"name": "Partner test 2",
|
||||
"email": "partner2@test.com",
|
||||
"title": title_doctor.id,
|
||||
"company_id": self.main_company.id,
|
||||
"country_id": country_cu.id,
|
||||
"category_id": [(6, 0, (category_8 | category_11).ids)],
|
||||
}
|
||||
partner = self.create_partner(partner_vals)
|
||||
contact.partner_id = partner
|
||||
contact._onchange_partner_mass_mailing_partner()
|
||||
self.check_mailing_contact_partner(contact)
|
||||
|
||||
def test_partners_merge(self):
|
||||
partner_1 = self.create_partner({"name": "Demo 1", "email": "demo1@demo.com"})
|
||||
partner_2 = self.create_partner({"name": "Demo 2", "email": "demo2@demo.com"})
|
||||
list_1 = self.create_mailing_list({"name": "List test Partners Merge 1"})
|
||||
list_2 = self.create_mailing_list({"name": "List test Partners Merge 2"})
|
||||
contact_1 = self.create_mailing_contact(
|
||||
{
|
||||
"email": partner_1.email,
|
||||
"name": partner_1.name,
|
||||
"partner_id": partner_1.id,
|
||||
"list_ids": [(6, 0, [list_1.id])],
|
||||
}
|
||||
)
|
||||
contact_2 = self.create_mailing_contact(
|
||||
{
|
||||
"email": partner_2.email,
|
||||
"name": partner_2.name,
|
||||
"partner_id": partner_2.id,
|
||||
"list_ids": [(6, 0, [list_1.id, list_2.id])],
|
||||
}
|
||||
)
|
||||
# Wizard partner merge (partner_1 + partner_2) in partner_i1
|
||||
wizard = self.env["base.partner.merge.automatic.wizard"].create(
|
||||
{"state": "option"}
|
||||
)
|
||||
wizard._merge((partner_1 + partner_2).ids, partner_1)
|
||||
contact = self.env["mailing.contact"].search(
|
||||
[("id", "in", (contact_1 + contact_2).ids)]
|
||||
)
|
||||
self.assertEqual(len(contact), 1)
|
||||
self.assertEqual(contact.list_ids.ids, (list_1 + list_2).ids)
|
39
mass_mailing_partner/tests/test_mail_mass_mailing_list.py
Normal file
39
mass_mailing_partner/tests/test_mail_mass_mailing_list.py
Normal file
@ -0,0 +1,39 @@
|
||||
# Copyright 2018 Tecnativa - Ernesto tejeda
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from . import base
|
||||
|
||||
|
||||
class MailMassMailingListCase(base.BaseCase):
|
||||
def test_create_mass_mailing_list(self):
|
||||
contact_test_1 = self.create_mailing_contact(
|
||||
{"name": "Contact test 1", "partner_id": self.partner.id}
|
||||
)
|
||||
contact_test_2 = self.create_mailing_contact(
|
||||
{"name": "Contact test 2", "partner_id": self.partner.id}
|
||||
)
|
||||
with self.assertRaises(ValidationError):
|
||||
self.create_mailing_list(
|
||||
{
|
||||
"name": "List test Create Mailing List",
|
||||
"contact_ids": [(6, 0, (contact_test_1 | contact_test_2).ids)],
|
||||
}
|
||||
)
|
||||
|
||||
def test_create_mass_mailing_list_with_subscription(self):
|
||||
contact_test_1 = self.create_mailing_contact(
|
||||
{"name": "Contact test 1", "partner_id": self.partner.id}
|
||||
)
|
||||
contact_test_2 = self.create_mailing_contact(
|
||||
{"name": "Contact test 2", "partner_id": self.partner.id}
|
||||
)
|
||||
with self.assertRaises(ValidationError):
|
||||
self.create_mailing_list(
|
||||
{
|
||||
"name": "List test Creat List With Subscription",
|
||||
"contact_ids": [(4, contact_test_1.id), (4, contact_test_2.id)],
|
||||
}
|
||||
)
|
@ -0,0 +1,22 @@
|
||||
# Copyright 2018 Tecnativa - Ernesto tejeda
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from . import base
|
||||
|
||||
|
||||
class MailMassMailingListContactRelCase(base.BaseCase):
|
||||
def test_create_mass_mailing_list(self):
|
||||
contact_test_1 = self.create_mailing_contact(
|
||||
{"name": "Contact test 1", "partner_id": self.partner.id}
|
||||
)
|
||||
contact_test_2 = self.create_mailing_contact(
|
||||
{"name": "Contact test 2", "partner_id": self.partner.id}
|
||||
)
|
||||
list_3 = self.create_mailing_list(
|
||||
{"name": "List test 3", "contact_ids": [(4, contact_test_1.id)]}
|
||||
)
|
||||
with self.assertRaises(ValidationError):
|
||||
list_3.contact_ids = [(4, contact_test_2.id)]
|
43
mass_mailing_partner/tests/test_partner_mail_list_wizard.py
Normal file
43
mass_mailing_partner/tests/test_partner_mail_list_wizard.py
Normal file
@ -0,0 +1,43 @@
|
||||
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
from . import base
|
||||
|
||||
|
||||
class PartnerMailListWizardCase(base.BaseCase):
|
||||
def test_add_to_mail_list(self):
|
||||
wizard = self.env["partner.mail.list.wizard"].create(
|
||||
{"mail_list_id": self.mailing_list.id}
|
||||
)
|
||||
wizard.partner_ids = [self.partner.id]
|
||||
wizard.add_to_mail_list()
|
||||
contacts = self.env["mailing.contact"].search(
|
||||
[("partner_id", "=", self.partner.id)]
|
||||
)
|
||||
cont = contacts.filtered(lambda r: wizard.mail_list_id in r.list_ids)
|
||||
self.assertEqual(len(cont), 1)
|
||||
self.check_mailing_contact_partner(cont)
|
||||
# This line does not create a new contact
|
||||
wizard.add_to_mail_list()
|
||||
self.assertEqual(len(self.partner.mass_mailing_contact_ids), 1)
|
||||
self.assertEqual(
|
||||
self.partner.mass_mailing_contact_ids.list_ids, self.mailing_list
|
||||
)
|
||||
|
||||
list_2 = self.create_mailing_list({"name": "Test Add to List"})
|
||||
wizard.mail_list_id = list_2
|
||||
wizard.add_to_mail_list()
|
||||
self.assertEqual(len(self.partner.mass_mailing_contact_ids), 1)
|
||||
self.assertEqual(
|
||||
self.partner.mass_mailing_contact_ids.list_ids, self.mailing_list | list_2
|
||||
)
|
||||
|
||||
partner = self.env["res.partner"].create({"name": "No email partner"})
|
||||
wizard.partner_ids = [partner.id]
|
||||
with self.assertRaises(UserError):
|
||||
wizard.add_to_mail_list()
|
61
mass_mailing_partner/tests/test_res_partner.py
Normal file
61
mass_mailing_partner/tests/test_res_partner.py
Normal file
@ -0,0 +1,61 @@
|
||||
# Copyright 2015 Tecnativa - Pedro M. Baeza
|
||||
# Copyright 2015 Tecnativa - Antonio Espinosa
|
||||
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# Copyright 2021 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from . import base
|
||||
|
||||
|
||||
class ResPartnerCase(base.BaseCase):
|
||||
def test_count_mass_mailing_contacts(self):
|
||||
self.create_mailing_contact(
|
||||
{"email": "partner@test.com", "list_ids": [[6, 0, [self.mailing_list.id]]]}
|
||||
)
|
||||
self.create_mailing_contact(
|
||||
{"email": "partner@test.com", "list_ids": [[6, 0, [self.mailing_list2.id]]]}
|
||||
)
|
||||
self.assertEqual(self.partner.mass_mailing_contacts_count, 2)
|
||||
|
||||
def test_write_res_partner(self):
|
||||
contact = self.create_mailing_contact(
|
||||
{"email": "partner@test.com", "list_ids": [[6, 0, [self.mailing_list.id]]]}
|
||||
)
|
||||
self.assertEqual(self.partner, contact.partner_id)
|
||||
|
||||
title_doctor = self.env.ref("base.res_partner_title_doctor")
|
||||
country_cu = self.env.ref("base.cu")
|
||||
category_8 = self.env.ref("base.res_partner_category_8")
|
||||
category_11 = self.env.ref("base.res_partner_category_11")
|
||||
self.partner.write(
|
||||
{
|
||||
"name": "Changed",
|
||||
"email": "partner@changed.com",
|
||||
"title": title_doctor.id,
|
||||
"company_id": self.main_company.id,
|
||||
"country_id": country_cu.id,
|
||||
"category_id": [(6, 0, (category_8 | category_11).ids)],
|
||||
}
|
||||
)
|
||||
self.check_mailing_contact_partner(contact)
|
||||
with self.assertRaises(ValidationError):
|
||||
self.partner.write({"email": False})
|
||||
|
||||
def test_write_res_partner_multi(self):
|
||||
self.assertEqual(len(self.partner.category_id.ids), 2)
|
||||
partner2 = self.partner.copy({"name": "Partner test 2"})
|
||||
self.partner.write({"category_id": [(4, self.category_3.id)]})
|
||||
self.assertEqual(len(self.partner.category_id.ids), 3)
|
||||
self.assertEqual(len(partner2.category_id.ids), 2)
|
||||
for partner in [self.partner, partner2]:
|
||||
self.create_mailing_contact(
|
||||
{"partner_id": partner.id, "list_ids": [[6, 0, [self.mailing_list.id]]]}
|
||||
)
|
||||
self.env["res.partner"].search(
|
||||
[("id", "in", (self.partner.id, partner2.id))]
|
||||
).write({"category_id": [(4, self.category_3.id)]})
|
||||
self.assertEqual(len(self.partner.category_id.ids), 3)
|
||||
self.assertEqual(len(partner2.category_id.ids), 3)
|
80
mass_mailing_partner/views/mailing_contact_view.xml
Normal file
80
mass_mailing_partner/views/mailing_contact_view.xml
Normal file
@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
||||
Copyright 2020 Tecnativa - Manuel Calero
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="view_mail_mass_mailing_contact_tree">
|
||||
<field name="name">mailing.contact.tree.inherit</field>
|
||||
<field name="model">mailing.contact</field>
|
||||
<field name="inherit_id" ref="mass_mailing.mailing_contact_view_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="email" position="after">
|
||||
<field name="partner_id" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_mail_mass_mailing_contact_form">
|
||||
<field name="name">mailing.contact.form.partner</field>
|
||||
<field name="model">mailing.contact</field>
|
||||
<field name="inherit_id" ref="mass_mailing.mailing_contact_view_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='email']/.." position="after">
|
||||
<field name="partner_id" />
|
||||
</xpath>
|
||||
<field name="title_id" position="attributes">
|
||||
<attribute
|
||||
name="attrs"
|
||||
>{'readonly': [('partner_id', '!=', False)]}</attribute>
|
||||
</field>
|
||||
<field name="email" position="attributes">
|
||||
<attribute
|
||||
name="attrs"
|
||||
>{'readonly': [('partner_id', '!=', False)]}</attribute>
|
||||
</field>
|
||||
<field name="name" position="attributes">
|
||||
<attribute
|
||||
name="attrs"
|
||||
>{'readonly': [('partner_id', '!=', False)]}</attribute>
|
||||
</field>
|
||||
<field name="company_name" position="attributes">
|
||||
<attribute
|
||||
name="attrs"
|
||||
>{'readonly': [('partner_id', '!=', False)]}</attribute>
|
||||
</field>
|
||||
<field name="country_id" position="attributes">
|
||||
<attribute
|
||||
name="attrs"
|
||||
>{'readonly': [('partner_id', '!=', False)]}</attribute>
|
||||
</field>
|
||||
<field name="tag_ids" position="attributes">
|
||||
<attribute
|
||||
name="attrs"
|
||||
>{'readonly': [('partner_id', '!=', False)]}</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_mail_mass_mailing_contact_search">
|
||||
<field name="name">Add partner search field and group by</field>
|
||||
<field name="model">mailing.contact</field>
|
||||
<field name="inherit_id" ref="mass_mailing.mailing_contact_view_search" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<field name="partner_id" />
|
||||
</field>
|
||||
<filter name="group_create_date" position="after">
|
||||
<filter
|
||||
string="Partner"
|
||||
name="group_partner"
|
||||
context="{'group_by': 'partner_id'}"
|
||||
/>
|
||||
</filter>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
47
mass_mailing_partner/views/mailing_trace_view.xml
Normal file
47
mass_mailing_partner/views/mailing_trace_view.xml
Normal file
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
||||
Copyright 2020 Tecnativa - Manuel Calero
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="mailing_trace_view_form">
|
||||
<field name="name">Add partner field</field>
|
||||
<field name="model">mailing.trace</field>
|
||||
<field name="inherit_id" ref="mass_mailing.mailing_trace_view_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="res_id" position="after">
|
||||
<field name="partner_id" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="mailing_trace_view_tree">
|
||||
<field name="name">Add partner column</field>
|
||||
<field name="model">mailing.trace</field>
|
||||
<field name="inherit_id" ref="mass_mailing.mailing_trace_view_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="sent" position="before">
|
||||
<field name="partner_id" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="mailing_trace_view_search">
|
||||
<field name="name">Add partner search field and group by</field>
|
||||
<field name="model">mailing.trace</field>
|
||||
<field name="inherit_id" ref="mass_mailing.mailing_trace_view_search" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="mass_mailing_id" position="after">
|
||||
<field name="partner_id" />
|
||||
</field>
|
||||
<filter name="group_reply_date" position="after">
|
||||
<filter
|
||||
string="Partner"
|
||||
name="group_partner"
|
||||
context="{'group_by': 'partner_id'}"
|
||||
/>
|
||||
</filter>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
25
mass_mailing_partner/views/mailing_view.xml
Normal file
25
mass_mailing_partner/views/mailing_view.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
Copyright 2020 Tecnativa - Manuel Calero
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="mailing_list_view_form">
|
||||
<field name="name">mailing.list.form</field>
|
||||
<field name="model">mailing.list</field>
|
||||
<field name="inherit_id" ref="mass_mailing.mailing_list_view_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[hasclass('oe_title')]" position="after">
|
||||
<group>
|
||||
<group>
|
||||
<field name="partner_mandatory" />
|
||||
<field name="partner_category" />
|
||||
</group>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
72
mass_mailing_partner/views/res_partner_view.xml
Normal file
72
mass_mailing_partner/views/res_partner_view.xml
Normal file
@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
Copyright 2015-16 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
||||
Copyright 2020 Tecnativa - Manuel Calero
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="view_partner_form">
|
||||
<field name="name">Partner Form with mailing contacts</field>
|
||||
<field name="model">res.partner</field>
|
||||
<field name="inherit_id" ref="base.view_partner_form" />
|
||||
<field
|
||||
name="groups_id"
|
||||
eval="[(4, ref('mass_mailing.group_mass_mailing_user'))]"
|
||||
/>
|
||||
<field name="arch" type="xml">
|
||||
<div name="button_box" position="inside">
|
||||
<button
|
||||
name="%(mass_mailing.action_view_mass_mailing_contacts)d"
|
||||
context="{'search_default_partner_id': active_id,
|
||||
'default_partner_id': active_id}"
|
||||
type="action"
|
||||
class="oe_stat_button"
|
||||
icon="fa-envelope-o"
|
||||
>
|
||||
<field
|
||||
name="mass_mailing_contacts_count"
|
||||
widget="statinfo"
|
||||
string="Mailing contacts"
|
||||
/>
|
||||
</button>
|
||||
<button
|
||||
name="%(mass_mailing.mailing_trace_action)d"
|
||||
context="{'search_default_partner_id': active_id,
|
||||
'default_partner_id': active_id}"
|
||||
type="action"
|
||||
class="oe_stat_button"
|
||||
icon="fa-envelope-o"
|
||||
>
|
||||
<field
|
||||
name="mass_mailing_stats_count"
|
||||
widget="statinfo"
|
||||
string="Mass mailing stats"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_res_partner_filter" model="ir.ui.view">
|
||||
<field name="name">Partner Search with mailing contacts</field>
|
||||
<field name="model">res.partner</field>
|
||||
<field name="inherit_id" ref="base.view_res_partner_filter" />
|
||||
<field
|
||||
name="groups_id"
|
||||
eval="[(4, ref('mass_mailing.group_mass_mailing_user'))]"
|
||||
/>
|
||||
<field name="priority">20</field>
|
||||
<field name="arch" type="xml">
|
||||
<field name="category_id" position="after">
|
||||
<field
|
||||
name="mass_mailing_contact_ids"
|
||||
string="Mailing List"
|
||||
filter_domain="[('mass_mailing_contact_ids.list_ids','ilike', self)]"
|
||||
/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
4
mass_mailing_partner/wizard/__init__.py
Normal file
4
mass_mailing_partner/wizard/__init__.py
Normal file
@ -0,0 +1,4 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import partner_mail_list_wizard
|
||||
from . import partner_merge
|
44
mass_mailing_partner/wizard/partner_mail_list_wizard.py
Normal file
44
mass_mailing_partner/wizard/partner_mail_list_wizard.py
Normal file
@ -0,0 +1,44 @@
|
||||
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
# Copyright 2020 Tecnativa - Manuel Calero
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import _, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class PartnerMailListWizard(models.TransientModel):
|
||||
_name = "partner.mail.list.wizard"
|
||||
_description = "Create contact mailing list"
|
||||
|
||||
mail_list_id = fields.Many2one(comodel_name="mailing.list", string="Mailing List")
|
||||
partner_ids = fields.Many2many(
|
||||
comodel_name="res.partner",
|
||||
relation="mail_list_wizard_partner",
|
||||
default=lambda self: self.env.context.get("active_ids"),
|
||||
)
|
||||
|
||||
def add_to_mail_list(self):
|
||||
contact_obj = self.env["mailing.contact"]
|
||||
partners = self.partner_ids
|
||||
|
||||
add_list = partners.filtered("mass_mailing_contact_ids")
|
||||
for partner in add_list:
|
||||
self.mail_list_id.contact_ids = [
|
||||
(4, partner.mass_mailing_contact_ids[0].id)
|
||||
]
|
||||
|
||||
to_create = partners - add_list
|
||||
for partner in to_create:
|
||||
if not partner.email:
|
||||
raise UserError(_("Partner '%s' has no email.") % partner.name)
|
||||
contact_vals = {
|
||||
"partner_id": partner.id,
|
||||
"list_ids": [(4, self.mail_list_id.id)],
|
||||
"title_id": partner.title or False,
|
||||
"company_name": partner.company_id.name or False,
|
||||
"country_id": partner.country_id or False,
|
||||
"tag_ids": partner.category_id or False,
|
||||
}
|
||||
contact_obj.create(contact_vals)
|
39
mass_mailing_partner/wizard/partner_mail_list_wizard.xml
Normal file
39
mass_mailing_partner/wizard/partner_mail_list_wizard.xml
Normal file
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
||||
Copyright 2020 Tecnativa - Manuel Calero
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
|
||||
<odoo>
|
||||
|
||||
<record id="action_partner_mail_list" model="ir.actions.act_window">
|
||||
<field name="name">Add to mailing list</field>
|
||||
<field name="res_model">partner.mail.list.wizard</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="binding_model_id" ref="base.model_res_partner" />
|
||||
<field name="binding_view_types">list</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="partner_mail_list_wizard_form">
|
||||
<field name="name">partner.mail.list.form</field>
|
||||
<field name="model">partner.mail.list.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Create contact mailing list">
|
||||
<group>
|
||||
<field name="mail_list_id" />
|
||||
</group>
|
||||
<footer>
|
||||
<button
|
||||
string="Add contacts to mailing list"
|
||||
name="add_to_mail_list"
|
||||
type="object"
|
||||
class="oe_highlight"
|
||||
/>
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
27
mass_mailing_partner/wizard/partner_merge.py
Normal file
27
mass_mailing_partner/wizard/partner_merge.py
Normal file
@ -0,0 +1,27 @@
|
||||
# Copyright 2020 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class BasePartnerMergeAutomaticWizard(models.TransientModel):
|
||||
_inherit = "base.partner.merge.automatic.wizard"
|
||||
|
||||
def _merge(self, partner_ids, dst_partner=None, extra_checks=True):
|
||||
if dst_partner:
|
||||
contacts = (
|
||||
self.env["mailing.contact"]
|
||||
.sudo()
|
||||
.search([("partner_id", "in", partner_ids)])
|
||||
)
|
||||
if contacts:
|
||||
contacts = contacts.sorted(
|
||||
lambda x: 1 if x.partner_id == dst_partner else 0
|
||||
)
|
||||
list_ids = contacts.mapped("list_ids").ids
|
||||
contacts[1:].unlink()
|
||||
contacts[0].partner_id = dst_partner
|
||||
contacts[0].list_ids = [(4, x) for x in list_ids]
|
||||
return super()._merge(
|
||||
partner_ids, dst_partner=dst_partner, extra_checks=extra_checks
|
||||
)
|
93
mass_mailing_unique/README.rst
Normal file
93
mass_mailing_unique/README.rst
Normal file
@ -0,0 +1,93 @@
|
||||
===============================
|
||||
Unique records for mass mailing
|
||||
===============================
|
||||
|
||||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
|
||||
:target: https://odoo-community.org/page/development-status
|
||||
:alt: Beta
|
||||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
|
||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
|
||||
:target: https://github.com/OCA/social/tree/14.0/mass_mailing_unique
|
||||
:alt: OCA/social
|
||||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||
:target: https://translation.odoo-community.org/projects/social-14-0/social-14-0-mass_mailing_unique
|
||||
:alt: Translate me on Weblate
|
||||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||
:target: https://runbot.odoo-community.org/runbot/205/14.0
|
||||
:alt: Try me on Runbot
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|
||||
This module extends the functionality of mass mailing lists to disable
|
||||
duplicate entries in list names and contact emails.
|
||||
|
||||
This way you will avoid conflicts when importing contacts to a list that has a
|
||||
duplicated name.
|
||||
|
||||
**Table of contents**
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
Before installing this module, you need to:
|
||||
|
||||
* Remove all duplicated list names.
|
||||
* Remove all duplicated emails in mailing contacts.
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mass_mailing_unique%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
|
||||
Do not contact contributors directly about support or help with technical issues.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Authors
|
||||
~~~~~~~
|
||||
|
||||
* Tecnativa
|
||||
|
||||
Contributors
|
||||
~~~~~~~~~~~~
|
||||
|
||||
* `Tecnativa <https://www.tecnativa.com>`_:
|
||||
|
||||
* Jairo Llopis
|
||||
* Vicent Cubells
|
||||
* Pedro M. Baeza
|
||||
* Ernesto Tejeda
|
||||
* `Camptocamp <https://www.camptocamp.com>`_
|
||||
|
||||
* Iván Todorovich <ivan.todorovich@gmail.com>
|
||||
|
||||
Maintainers
|
||||
~~~~~~~~~~~
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
.. image:: https://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: https://odoo-community.org
|
||||
|
||||
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
This module is part of the `OCA/social <https://github.com/OCA/social/tree/14.0/mass_mailing_unique>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
6
mass_mailing_unique/__init__.py
Normal file
6
mass_mailing_unique/__init__.py
Normal file
@ -0,0 +1,6 @@
|
||||
# Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
|
||||
# Copyright 2016 Tecnativa - Vicent Cubells
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import models
|
||||
from .hooks import pre_init_hook
|
16
mass_mailing_unique/__manifest__.py
Normal file
16
mass_mailing_unique/__manifest__.py
Normal file
@ -0,0 +1,16 @@
|
||||
# Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
|
||||
# Copyright 2016 Tecnativa - Vicent Cubells
|
||||
# Copyright 2018 Tecnativa - Ernesto Tejeda
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
"name": "Unique records for mass mailing",
|
||||
"summary": "Avoids duplicate mailing lists and contacts",
|
||||
"version": "14.0.1.0.0",
|
||||
"category": "Marketing",
|
||||
"website": "https://github.com/OCA/social",
|
||||
"author": "Tecnativa, Odoo Community Association (OCA)",
|
||||
"license": "AGPL-3",
|
||||
"depends": ["mass_mailing"],
|
||||
"pre_init_hook": "pre_init_hook",
|
||||
}
|
48
mass_mailing_unique/hooks.py
Normal file
48
mass_mailing_unique/hooks.py
Normal file
@ -0,0 +1,48 @@
|
||||
# Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
|
||||
# Copyright 2016 Tecnativa - Vicent Cubells
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
def pre_init_hook(cr):
|
||||
"""Make sure there are no duplicates before installing the module.
|
||||
|
||||
If you define an unique key in Odoo that cannot be applied, Odoo will log a
|
||||
warning and install the module without that constraint. Since this module
|
||||
is useless without those constraints, we check here if all will work before
|
||||
installing, and provide a user-friendly message in case of failure.
|
||||
"""
|
||||
errors = list()
|
||||
# Search for duplicates in emails
|
||||
cr.execute(
|
||||
"""
|
||||
SELECT email_normalized, COUNT(id) as count
|
||||
FROM mailing_contact
|
||||
GROUP BY email_normalized
|
||||
HAVING COUNT(id) > 1
|
||||
"""
|
||||
)
|
||||
for result in cr.fetchall():
|
||||
errors.append(
|
||||
"There are {1} mailing contacts with the same email: {0}".format(*result)
|
||||
)
|
||||
# Search for duplicates in list's name
|
||||
cr.execute(
|
||||
"""
|
||||
SELECT name, COUNT(id) as count
|
||||
FROM mailing_list
|
||||
GROUP BY name
|
||||
HAVING COUNT(id) > 1
|
||||
"""
|
||||
)
|
||||
for result in cr.fetchall():
|
||||
errors.append(
|
||||
"There are {1} mailing lists with the same name: {0}.".format(*result)
|
||||
)
|
||||
# Abort if duplicates are found
|
||||
if errors:
|
||||
raise ValidationError(
|
||||
_("Unable to install module mass_mailing_unique:\n%s", "\n".join(errors))
|
||||
)
|
2
mass_mailing_unique/models/__init__.py
Normal file
2
mass_mailing_unique/models/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from . import mailing_contact
|
||||
from . import mailing_list
|
17
mass_mailing_unique/models/mailing_contact.py
Normal file
17
mass_mailing_unique/models/mailing_contact.py
Normal file
@ -0,0 +1,17 @@
|
||||
# Copyright 2018 Tecnativa - Ernesto Tejeda
|
||||
# Copyright 2021 Camptocamp - Iván Todorovich
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class MailingContact(models.Model):
|
||||
_inherit = "mailing.contact"
|
||||
|
||||
_sql_constraints = [
|
||||
(
|
||||
"unique_email",
|
||||
"UNIQUE(email_normalized)",
|
||||
"There's already a contact with this email address",
|
||||
)
|
||||
]
|
18
mass_mailing_unique/models/mailing_list.py
Normal file
18
mass_mailing_unique/models/mailing_list.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
|
||||
# Copyright 2016 Tecnativa - Vicent Cubells
|
||||
# Copyright 2021 Camptocamp - Iván Todorovich
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class MailingList(models.Model):
|
||||
_inherit = "mailing.list"
|
||||
|
||||
_sql_constraints = [
|
||||
(
|
||||
"unique_name",
|
||||
"UNIQUE(name)",
|
||||
"Cannot have more than one lists with the same name.",
|
||||
)
|
||||
]
|
9
mass_mailing_unique/readme/CONTRIBUTORS.rst
Normal file
9
mass_mailing_unique/readme/CONTRIBUTORS.rst
Normal file
@ -0,0 +1,9 @@
|
||||
* `Tecnativa <https://www.tecnativa.com>`_:
|
||||
|
||||
* Jairo Llopis
|
||||
* Vicent Cubells
|
||||
* Pedro M. Baeza
|
||||
* Ernesto Tejeda
|
||||
* `Camptocamp <https://www.camptocamp.com>`_
|
||||
|
||||
* Iván Todorovich <ivan.todorovich@gmail.com>
|
5
mass_mailing_unique/readme/DESCRIPTION.rst
Normal file
5
mass_mailing_unique/readme/DESCRIPTION.rst
Normal file
@ -0,0 +1,5 @@
|
||||
This module extends the functionality of mass mailing lists to disable
|
||||
duplicate entries in list names and contact emails.
|
||||
|
||||
This way you will avoid conflicts when importing contacts to a list that has a
|
||||
duplicated name.
|
4
mass_mailing_unique/readme/INSTALL.rst
Normal file
4
mass_mailing_unique/readme/INSTALL.rst
Normal file
@ -0,0 +1,4 @@
|
||||
Before installing this module, you need to:
|
||||
|
||||
* Remove all duplicated list names.
|
||||
* Remove all duplicated emails in mailing contacts.
|
BIN
mass_mailing_unique/static/description/icon.png
Normal file
BIN
mass_mailing_unique/static/description/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
445
mass_mailing_unique/static/description/index.html
Normal file
445
mass_mailing_unique/static/description/index.html
Normal file
@ -0,0 +1,445 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
|
||||
<title>Unique records for mass mailing</title>
|
||||
<style type="text/css">
|
||||
|
||||
/*
|
||||
:Author: David Goodger (goodger@python.org)
|
||||
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
|
||||
:Copyright: This stylesheet has been placed in the public domain.
|
||||
|
||||
Default cascading style sheet for the HTML output of Docutils.
|
||||
|
||||
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
|
||||
customize this style sheet.
|
||||
*/
|
||||
|
||||
/* used to remove borders from tables and images */
|
||||
.borderless, table.borderless td, table.borderless th {
|
||||
border: 0 }
|
||||
|
||||
table.borderless td, table.borderless th {
|
||||
/* Override padding for "table.docutils td" with "! important".
|
||||
The right padding separates the table cells. */
|
||||
padding: 0 0.5em 0 0 ! important }
|
||||
|
||||
.first {
|
||||
/* Override more specific margin styles with "! important". */
|
||||
margin-top: 0 ! important }
|
||||
|
||||
.last, .with-subtitle {
|
||||
margin-bottom: 0 ! important }
|
||||
|
||||
.hidden {
|
||||
display: none }
|
||||
|
||||
.subscript {
|
||||
vertical-align: sub;
|
||||
font-size: smaller }
|
||||
|
||||
.superscript {
|
||||
vertical-align: super;
|
||||
font-size: smaller }
|
||||
|
||||
a.toc-backref {
|
||||
text-decoration: none ;
|
||||
color: black }
|
||||
|
||||
blockquote.epigraph {
|
||||
margin: 2em 5em ; }
|
||||
|
||||
dl.docutils dd {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Uncomment (and remove this text!) to get bold-faced definition list terms
|
||||
dl.docutils dt {
|
||||
font-weight: bold }
|
||||
*/
|
||||
|
||||
div.abstract {
|
||||
margin: 2em 5em }
|
||||
|
||||
div.abstract p.topic-title {
|
||||
font-weight: bold ;
|
||||
text-align: center }
|
||||
|
||||
div.admonition, div.attention, div.caution, div.danger, div.error,
|
||||
div.hint, div.important, div.note, div.tip, div.warning {
|
||||
margin: 2em ;
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.admonition p.admonition-title, div.hint p.admonition-title,
|
||||
div.important p.admonition-title, div.note p.admonition-title,
|
||||
div.tip p.admonition-title {
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
div.attention p.admonition-title, div.caution p.admonition-title,
|
||||
div.danger p.admonition-title, div.error p.admonition-title,
|
||||
div.warning p.admonition-title, .code .error {
|
||||
color: red ;
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
/* Uncomment (and remove this text!) to get reduced vertical space in
|
||||
compound paragraphs.
|
||||
div.compound .compound-first, div.compound .compound-middle {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
div.compound .compound-last, div.compound .compound-middle {
|
||||
margin-top: 0.5em }
|
||||
*/
|
||||
|
||||
div.dedication {
|
||||
margin: 2em 5em ;
|
||||
text-align: center ;
|
||||
font-style: italic }
|
||||
|
||||
div.dedication p.topic-title {
|
||||
font-weight: bold ;
|
||||
font-style: normal }
|
||||
|
||||
div.figure {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
div.footer, div.header {
|
||||
clear: both;
|
||||
font-size: smaller }
|
||||
|
||||
div.line-block {
|
||||
display: block ;
|
||||
margin-top: 1em ;
|
||||
margin-bottom: 1em }
|
||||
|
||||
div.line-block div.line-block {
|
||||
margin-top: 0 ;
|
||||
margin-bottom: 0 ;
|
||||
margin-left: 1.5em }
|
||||
|
||||
div.sidebar {
|
||||
margin: 0 0 0.5em 1em ;
|
||||
border: medium outset ;
|
||||
padding: 1em ;
|
||||
background-color: #ffffee ;
|
||||
width: 40% ;
|
||||
float: right ;
|
||||
clear: right }
|
||||
|
||||
div.sidebar p.rubric {
|
||||
font-family: sans-serif ;
|
||||
font-size: medium }
|
||||
|
||||
div.system-messages {
|
||||
margin: 5em }
|
||||
|
||||
div.system-messages h1 {
|
||||
color: red }
|
||||
|
||||
div.system-message {
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.system-message p.system-message-title {
|
||||
color: red ;
|
||||
font-weight: bold }
|
||||
|
||||
div.topic {
|
||||
margin: 2em }
|
||||
|
||||
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
|
||||
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
|
||||
margin-top: 0.4em }
|
||||
|
||||
h1.title {
|
||||
text-align: center }
|
||||
|
||||
h2.subtitle {
|
||||
text-align: center }
|
||||
|
||||
hr.docutils {
|
||||
width: 75% }
|
||||
|
||||
img.align-left, .figure.align-left, object.align-left, table.align-left {
|
||||
clear: left ;
|
||||
float: left ;
|
||||
margin-right: 1em }
|
||||
|
||||
img.align-right, .figure.align-right, object.align-right, table.align-right {
|
||||
clear: right ;
|
||||
float: right ;
|
||||
margin-left: 1em }
|
||||
|
||||
img.align-center, .figure.align-center, object.align-center {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
table.align-center {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.align-left {
|
||||
text-align: left }
|
||||
|
||||
.align-center {
|
||||
clear: both ;
|
||||
text-align: center }
|
||||
|
||||
.align-right {
|
||||
text-align: right }
|
||||
|
||||
/* reset inner alignment in figures */
|
||||
div.align-right {
|
||||
text-align: inherit }
|
||||
|
||||
/* div.align-center * { */
|
||||
/* text-align: left } */
|
||||
|
||||
.align-top {
|
||||
vertical-align: top }
|
||||
|
||||
.align-middle {
|
||||
vertical-align: middle }
|
||||
|
||||
.align-bottom {
|
||||
vertical-align: bottom }
|
||||
|
||||
ol.simple, ul.simple {
|
||||
margin-bottom: 1em }
|
||||
|
||||
ol.arabic {
|
||||
list-style: decimal }
|
||||
|
||||
ol.loweralpha {
|
||||
list-style: lower-alpha }
|
||||
|
||||
ol.upperalpha {
|
||||
list-style: upper-alpha }
|
||||
|
||||
ol.lowerroman {
|
||||
list-style: lower-roman }
|
||||
|
||||
ol.upperroman {
|
||||
list-style: upper-roman }
|
||||
|
||||
p.attribution {
|
||||
text-align: right ;
|
||||
margin-left: 50% }
|
||||
|
||||
p.caption {
|
||||
font-style: italic }
|
||||
|
||||
p.credits {
|
||||
font-style: italic ;
|
||||
font-size: smaller }
|
||||
|
||||
p.label {
|
||||
white-space: nowrap }
|
||||
|
||||
p.rubric {
|
||||
font-weight: bold ;
|
||||
font-size: larger ;
|
||||
color: maroon ;
|
||||
text-align: center }
|
||||
|
||||
p.sidebar-title {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold ;
|
||||
font-size: larger }
|
||||
|
||||
p.sidebar-subtitle {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
p.topic-title {
|
||||
font-weight: bold }
|
||||
|
||||
pre.address {
|
||||
margin-bottom: 0 ;
|
||||
margin-top: 0 ;
|
||||
font: inherit }
|
||||
|
||||
pre.literal-block, pre.doctest-block, pre.math, pre.code {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
pre.code .ln { color: grey; } /* line numbers */
|
||||
pre.code, code { background-color: #eeeeee }
|
||||
pre.code .comment, code .comment { color: #5C6576 }
|
||||
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
|
||||
pre.code .literal.string, code .literal.string { color: #0C5404 }
|
||||
pre.code .name.builtin, code .name.builtin { color: #352B84 }
|
||||
pre.code .deleted, code .deleted { background-color: #DEB0A1}
|
||||
pre.code .inserted, code .inserted { background-color: #A3D289}
|
||||
|
||||
span.classifier {
|
||||
font-family: sans-serif ;
|
||||
font-style: oblique }
|
||||
|
||||
span.classifier-delimiter {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
span.interpreted {
|
||||
font-family: sans-serif }
|
||||
|
||||
span.option {
|
||||
white-space: nowrap }
|
||||
|
||||
span.pre {
|
||||
white-space: pre }
|
||||
|
||||
span.problematic {
|
||||
color: red }
|
||||
|
||||
span.section-subtitle {
|
||||
/* font-size relative to parent (h1..h6 element) */
|
||||
font-size: 80% }
|
||||
|
||||
table.citation {
|
||||
border-left: solid 1px gray;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docinfo {
|
||||
margin: 2em 4em }
|
||||
|
||||
table.docutils {
|
||||
margin-top: 0.5em ;
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
table.footnote {
|
||||
border-left: solid 1px black;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docutils td, table.docutils th,
|
||||
table.docinfo td, table.docinfo th {
|
||||
padding-left: 0.5em ;
|
||||
padding-right: 0.5em ;
|
||||
vertical-align: top }
|
||||
|
||||
table.docutils th.field-name, table.docinfo th.docinfo-name {
|
||||
font-weight: bold ;
|
||||
text-align: left ;
|
||||
white-space: nowrap ;
|
||||
padding-left: 0 }
|
||||
|
||||
/* "booktabs" style (no vertical lines) */
|
||||
table.docutils.booktabs {
|
||||
border: 0px;
|
||||
border-top: 2px solid;
|
||||
border-bottom: 2px solid;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
table.docutils.booktabs * {
|
||||
border: 0px;
|
||||
}
|
||||
table.docutils.booktabs th {
|
||||
border-bottom: thin solid;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
|
||||
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
|
||||
font-size: 100% }
|
||||
|
||||
ul.auto-toc {
|
||||
list-style-type: none }
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document" id="unique-records-for-mass-mailing">
|
||||
<h1 class="title">Unique records for mass mailing</h1>
|
||||
|
||||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/social/tree/14.0/mass_mailing_unique"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/social-14-0/social-14-0-mass_mailing_unique"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/205/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||
<p>This module extends the functionality of mass mailing lists to disable
|
||||
duplicate entries in list names and contact emails.</p>
|
||||
<p>This way you will avoid conflicts when importing contacts to a list that has a
|
||||
duplicated name.</p>
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
<ul class="simple">
|
||||
<li><a class="reference internal" href="#installation" id="id1">Installation</a></li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="installation">
|
||||
<h1><a class="toc-backref" href="#id1">Installation</a></h1>
|
||||
<p>Before installing this module, you need to:</p>
|
||||
<ul class="simple">
|
||||
<li>Remove all duplicated list names.</li>
|
||||
<li>Remove all duplicated emails in mailing contacts.</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
|
||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mass_mailing_unique%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||
</div>
|
||||
<div class="section" id="credits">
|
||||
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
|
||||
<div class="section" id="authors">
|
||||
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Tecnativa</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="contributors">
|
||||
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
|
||||
<ul>
|
||||
<li><p class="first"><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:</p>
|
||||
<ul class="simple">
|
||||
<li>Jairo Llopis</li>
|
||||
<li>Vicent Cubells</li>
|
||||
<li>Pedro M. Baeza</li>
|
||||
<li>Ernesto Tejeda</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><p class="first"><a class="reference external" href="https://www.camptocamp.com">Camptocamp</a></p>
|
||||
<blockquote>
|
||||
<ul class="simple">
|
||||
<li>Iván Todorovich <<a class="reference external" href="mailto:ivan.todorovich@gmail.com">ivan.todorovich@gmail.com</a>></li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
|
||||
<p>This module is maintained by the OCA.</p>
|
||||
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
|
||||
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.</p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/14.0/mass_mailing_unique">OCA/social</a> project on GitHub.</p>
|
||||
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
3
mass_mailing_unique/tests/__init__.py
Normal file
3
mass_mailing_unique/tests/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import test_mass_mailing_unique
|
110
mass_mailing_unique/tests/test_mass_mailing_unique.py
Normal file
110
mass_mailing_unique/tests/test_mass_mailing_unique.py
Normal file
@ -0,0 +1,110 @@
|
||||
# Copyright 2016 Tecnativa - Pedro M. Baeza
|
||||
# Copyright 2021 Camptocamp - Iván Todorovich
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from psycopg2 import IntegrityError
|
||||
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests import common
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
from ..hooks import pre_init_hook
|
||||
|
||||
|
||||
class TestMassMailingUnique(common.SavepointCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.mailing_list = cls.env.ref("mass_mailing.mailing_list_data")
|
||||
cls.mailing_contact = cls.env["mailing.contact"].create(
|
||||
{
|
||||
"name": "John Doe",
|
||||
"email": "john.doe@example.com",
|
||||
"list_ids": [(6, 0, cls.mailing_list.ids)],
|
||||
}
|
||||
)
|
||||
|
||||
def test_init_hook_list_mailing_list(self):
|
||||
# Disable temporarily the constraint
|
||||
self.env.cr.execute(
|
||||
"""
|
||||
ALTER TABLE mailing_list
|
||||
DROP CONSTRAINT mailing_list_unique_name
|
||||
"""
|
||||
)
|
||||
# Create another list with the same exact name
|
||||
self.env["mailing.list"].create({"name": self.mailing_list.name})
|
||||
self.env["mailing.list"].flush()
|
||||
with self.assertRaises(ValidationError):
|
||||
pre_init_hook(self.env.cr)
|
||||
|
||||
def test_init_hook_list_mailing_contact(self):
|
||||
# Disable temporarily the constraint
|
||||
self.env.cr.execute(
|
||||
"""
|
||||
ALTER TABLE mailing_contact
|
||||
DROP CONSTRAINT mailing_contact_unique_email
|
||||
"""
|
||||
)
|
||||
# Create another list with the same exact name
|
||||
self.env["mailing.contact"].create(
|
||||
{
|
||||
"name": f"{self.mailing_contact.name} (2)",
|
||||
"email": self.mailing_contact.email,
|
||||
}
|
||||
)
|
||||
self.env["mailing.contact"].flush()
|
||||
with self.assertRaises(ValidationError):
|
||||
pre_init_hook(self.env.cr)
|
||||
|
||||
def test_mailing_contact_unique_email_exact(self):
|
||||
"""Create a contact with the same exact email"""
|
||||
with mute_logger("odoo.sql_db"):
|
||||
with self.assertRaisesRegex(IntegrityError, "mailing_contact_unique_email"):
|
||||
self.env["mailing.contact"].create(
|
||||
{
|
||||
"name": "John Doe (2)",
|
||||
"email": "john.doe@example.com",
|
||||
}
|
||||
)
|
||||
self.env["mailing.contact"].flush()
|
||||
|
||||
def test_mailing_contact_unique_email_same(self):
|
||||
"""Create a contact with the same email (not exact though)"""
|
||||
with mute_logger("odoo.sql_db"):
|
||||
with self.assertRaisesRegex(IntegrityError, "mailing_contact_unique_email"):
|
||||
self.env["mailing.contact"].create(
|
||||
{
|
||||
"name": "John Doe (2)",
|
||||
"email": "<John Doe> John.DOE@example.com",
|
||||
}
|
||||
)
|
||||
self.env["mailing.contact"].flush()
|
||||
|
||||
def test_mailing_contact_unique_email_ok(self):
|
||||
"""Create a contact with another email"""
|
||||
self.env["mailing.contact"].create(
|
||||
{
|
||||
"name": "Jane Doe",
|
||||
"email": "jane.doe@example.com",
|
||||
}
|
||||
)
|
||||
|
||||
def test_mailing_list_unique_name_duplicated(self):
|
||||
"""Create a mailing list with the same name"""
|
||||
with mute_logger("odoo.sql_db"):
|
||||
with self.assertRaisesRegex(IntegrityError, "mailing_list_unique_name"):
|
||||
self.env["mailing.list"].create(
|
||||
{
|
||||
"name": self.mailing_list.name,
|
||||
}
|
||||
)
|
||||
self.env["mailing.list"].flush()
|
||||
|
||||
def test_mailing_list_unique_name_ok(self):
|
||||
"""Create a mailing list with another name"""
|
||||
self.env["mailing.list"].create(
|
||||
{
|
||||
"name": "Another mailing list",
|
||||
}
|
||||
)
|
Loading…
Reference in New Issue
Block a user