Skip to content

Commit

Permalink
Merge PR #1529 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by yajo
  • Loading branch information
OCA-git-bot committed Dec 30, 2024
2 parents ddf6d2e + 8ac9269 commit 201781c
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 42 deletions.
4 changes: 4 additions & 0 deletions mass_mailing_list_dynamic/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ Contributors

* Nguyễn Minh Chiến <[email protected]>

* `Moduon <https://www.moduon.team>`_:

* Jairo Llopis

Other credits
~~~~~~~~~~~~~

Expand Down
4 changes: 4 additions & 0 deletions mass_mailing_list_dynamic/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@
* `Trobz <https://trobz.com>`_:

* Nguyễn Minh Chiến <[email protected]>

* `Moduon <https://www.moduon.team>`_:

* Jairo Llopis
19 changes: 14 additions & 5 deletions mass_mailing_list_dynamic/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?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>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* 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 }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -479,6 +479,13 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
</ul>
</blockquote>
</li>
<li><p class="first"><a class="reference external" href="https://www.moduon.team">Moduon</a>:</p>
<blockquote>
<ul class="simple">
<li>Jairo Llopis</li>
</ul>
</blockquote>
</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand All @@ -488,7 +495,9 @@ <h2><a class="toc-backref" href="#toc-entry-7">Other credits</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-8">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>
<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>
Expand Down
23 changes: 19 additions & 4 deletions mass_mailing_list_dynamic/tests/test_dynamic_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ class DynamicListCase(common.TransactionCase):
def setUpClass(cls):
super().setUpClass()
cls.tag = cls.env["res.partner.category"].create({"name": "testing tag"})
cls.partners = cls.env["res.partner"]
for number in range(5):
cls.partners |= cls.partners.create(
cls.partners = cls.env["res.partner"].create(
[
{
"name": "partner %d" % number,
"category_id": [(4, cls.tag.id, False)],
"email": "%[email protected]" % number,
}
)
for number in range(5)
]
)
cls.list = cls.env["mailing.list"].create(
{
"name": "test list",
Expand Down Expand Up @@ -180,3 +181,17 @@ def test_partners_merge(self):
wizard.action_merge()
self.assertTrue(partner_1.id in self.list.contact_ids.mapped("partner_id").ids)
self.assertTrue(partner_1.id in list2.contact_ids.mapped("partner_id").ids)

def test_synced_contacts_can_be_bounced(self):
self.list.sync_method = "full"
self.list.action_sync()
contact = self.env["mailing.contact"].search(
[
("list_ids", "in", self.list.ids),
("partner_id", "=", self.partners[0].id),
]
)
# A bounce arrives through fetchmail
contact._message_receive_bounce(contact.email, contact.partner_id)
# The contact is marked as bounced
self.assertEqual(contact.message_bounce, 1)
4 changes: 4 additions & 0 deletions mass_mailing_partner/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ Contributors

* Nguyễn Minh Chiến <[email protected]>

* `Moduon <https://www.moduon.team>`_:

* Jairo Llopis

Other credits
~~~~~~~~~~~~~

Expand Down
45 changes: 20 additions & 25 deletions mass_mailing_partner/models/mailing_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,30 @@ def _onchange_partner_mass_mailing_partner(self):
)
self.country_id = self.partner_id.country_id

@api.model
def _get_contact_vals(self, origin_vals):
record = self.new(origin_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=origin_vals.get("subscription_list_ids", []),
list_ids=origin_vals.get("list_ids", []),
)
if new_vals.get("partner_id") and "tag_ids" in new_vals:
# When there is a partner, tag_ids must get value from the compute function
# otherwise, its values will be different from partner
del new_vals["tag_ids"]
return new_vals
def _overwrite_partner(self, vals, creating=False):
"""Overwrite partner and update contact data if needed."""
self.ensure_one()
if self.env.context.get("mass_mailing_partner_writing"):
return
_self = self.with_context(mass_mailing_partner_writing=True)
prev_partner = _self.partner_id
if "partner_id" not in vals:
_self._set_partner()
if creating or prev_partner != _self.partner_id:
_self._onchange_partner_mass_mailing_partner()

@api.model_create_multi
def create(self, vals_list):
new_vals_list = []
for vals in vals_list:
new_vals = self._get_contact_vals(vals)
new_vals_list.append(new_vals)
return super().create(new_vals_list)
result = super().create(vals_list)
for contact, vals in zip(result, vals_list):
contact._overwrite_partner(vals, True)
return result

def write(self, vals):
result = super().write(vals)
for contact in self:
origin_vals = contact.copy_data(vals)[0]
new_vals = self._get_contact_vals(origin_vals)
super(MailingContact, contact).write(new_vals)
return True
contact._overwrite_partner(vals)
return result

def _get_categories(self):
ca_ids = (
Expand Down Expand Up @@ -113,6 +106,8 @@ def _set_partner(self):
email = self.email.strip()
partner = m_partner.search([("email", "=ilike", email)], limit=1)
if partner:
if partner == self.partner_id:
return
# Partner found
self.partner_id = partner
else:
Expand Down
4 changes: 4 additions & 0 deletions mass_mailing_partner/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
* `Trobz <https://trobz.com>`_:

* Nguyễn Minh Chiến <[email protected]>

* `Moduon <https://www.moduon.team>`_:

* Jairo Llopis
19 changes: 14 additions & 5 deletions mass_mailing_partner/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?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>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* 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 }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -447,6 +447,13 @@ <h1>Contributors</h1>
</ul>
</blockquote>
</li>
<li><p class="first"><a class="reference external" href="https://www.moduon.team">Moduon</a>:</p>
<blockquote>
<ul class="simple">
<li>Jairo Llopis</li>
</ul>
</blockquote>
</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand All @@ -456,7 +463,9 @@ <h1>Other credits</h1>
<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>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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.partner_ids = self.partner
wizard.add_to_mail_list()
contacts = self.env["mailing.contact"].search(
[("partner_id", "=", self.partner.id)]
Expand Down
4 changes: 2 additions & 2 deletions mass_mailing_partner/wizard/partner_mail_list_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def add_to_mail_list(self):
contact_vals = {
"partner_id": partner.id,
"list_ids": [(4, self.mail_list_id.id)],
"title_id": partner.title or False,
"title_id": partner.title.id or False,
"company_name": partner.company_id.name or False,
"country_id": partner.country_id or False,
"country_id": partner.country_id.id or False,
}
contact_obj.create(contact_vals)

0 comments on commit 201781c

Please sign in to comment.