Browse Source

[MIG] mass_mailing_list_dynamic: Migration to 11.0

pull/284/head
Damien Carlier 7 years ago
committed by Pedro M. Baeza
parent
commit
168e1c0418
  1. 1
      mass_mailing_list_dynamic/__init__.py
  2. 3
      mass_mailing_list_dynamic/__manifest__.py
  3. 1
      mass_mailing_list_dynamic/models/__init__.py
  4. 1
      mass_mailing_list_dynamic/models/mail_mass_mailing.py
  5. 10
      mass_mailing_list_dynamic/models/mail_mass_mailing_contact.py
  6. 35
      mass_mailing_list_dynamic/models/mail_mass_mailing_list.py
  7. 1
      mass_mailing_list_dynamic/models/res_partner.py
  8. 1
      mass_mailing_list_dynamic/tests/__init__.py
  9. 11
      mass_mailing_list_dynamic/tests/test_dynamic_lists.py
  10. 5
      mass_mailing_list_dynamic/views/mail_mass_mailing_list_view.xml
  11. 1
      mass_mailing_list_dynamic/wizards/__init__.py
  12. 1
      mass_mailing_list_dynamic/wizards/mail_mass_mailing_load_filter.py

1
mass_mailing_list_dynamic/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import models

3
mass_mailing_list_dynamic/__manifest__.py

@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Tecnativa - Jairo Llopis
# Copyright 2018 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Dynamic Mass Mailing Lists",
"summary": "Mass mailing lists that get autopopulated",
"version": "10.0.1.2.0",
"version": "11.0.1.0.0",
"category": "Marketing",
"website": "https://github.com/OCA/social",
"author": "Tecnativa, Odoo Community Association (OCA)",

1
mass_mailing_list_dynamic/models/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import mail_mass_mailing

1
mass_mailing_list_dynamic/models/mail_mass_mailing.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Tecnativa - Jairo Llopis
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

10
mass_mailing_list_dynamic/models/mail_mass_mailing_contact.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Tecnativa - Jairo Llopis
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
@ -9,12 +8,15 @@ from odoo.exceptions import ValidationError
class MassMailingContact(models.Model):
_inherit = "mail.mass_mailing.contact"
@api.constrains("partner_id", "list_id", "name", "email")
@api.constrains("partner_id", "list_ids", "name", "email")
def _check_no_manual_edits_on_fully_synced_lists(self):
if self.env.context.get("syncing"):
return
if any((one.list_id.dynamic and
one.list_id.sync_method == "full") for one in self):
for one in self:
if any((list.dynamic and
list.sync_method == "full") for list in one.list_ids):
# if any((one.list_id.dynamic and
# one.list_id.sync_method == "full") for one in self):
raise ValidationError(
_("Cannot edit manually contacts in a fully "
"synchronized list. Change its sync method or execute "

35
mass_mailing_list_dynamic/models/mail_mass_mailing_list.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Tecnativa - Jairo Llopis
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
@ -47,18 +46,36 @@ class MassMailingList(models.Model):
desired_partners = Partner.search(sync_domain)
# Remove undesired contacts when synchronization is full
if one.sync_method == "full":
Contact.search([
("list_id", "=", one.id),
("partner_id", "not in", desired_partners.ids),
]).unlink()
current_contacts = Contact.search([("list_id", "=", one.id)])
current_partners = current_contacts.mapped("partner_id")
contacts = Contact.search([("list_ids", "in", [one.id]),
("partner_id", "not in",
desired_partners.ids)])
for contact in contacts:
# No delete contacts with other lists
if len(contact.list_ids) > 1:
contact.write({'list_ids': [(3, one.id, False)]})
else:
contact.unlink()
current_contacts_in_list = \
Contact.search([("list_ids", "in", [one.id])])
current_partners_in_list = \
current_contacts_in_list.mapped("partner_id")
current_contacts_not_in_list = \
Contact.search([("partner_id", "in", desired_partners.ids),
("list_ids", "not in", [one.id])])
current_partners_not_in_list = \
current_contacts_not_in_list.mapped("partner_id")
# Add new contacts
for partner in desired_partners - current_partners:
for partner in desired_partners - current_partners_in_list - \
current_partners_not_in_list:
Contact.create({
"list_id": one.id,
"list_ids": [(4, one.id, False)],
"partner_id": partner.id,
})
# Add list in existing contacts
for contact in current_contacts_not_in_list:
contact.write({
"list_ids": [(4, one.id, False)],
})
one.is_synced = True
# Invalidate cached contact count
self.invalidate_cache(["contact_nbr"], dynamic.ids)

1
mass_mailing_list_dynamic/models/res_partner.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

1
mass_mailing_list_dynamic/tests/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import test_dynamic_lists

11
mass_mailing_list_dynamic/tests/test_dynamic_lists.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Tecnativa - Jairo Llopis
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
@ -45,7 +44,7 @@ class DynamicListCase(common.SavepointCase):
self.list.dynamic = False
# Create contact for partner 0 in unsynced list
contact0 = Contact.create({
"list_id": self.list.id,
"list_ids": [(4, self.list.id, False)],
"partner_id": self.partners[0].id,
})
self.assertEqual(self.list.contact_nbr, 1)
@ -57,7 +56,7 @@ class DynamicListCase(common.SavepointCase):
# Set list as full-synced
self.list.sync_method = "full"
Contact.search([
("list_id", "=", self.list.id),
("list_ids", "in", [self.list.id]),
("partner_id", "=", self.partners[2].id),
]).unlink()
self.list.action_sync()
@ -66,11 +65,11 @@ class DynamicListCase(common.SavepointCase):
# Cannot add or edit contacts in fully synced lists
with self.assertRaises(ValidationError):
Contact.create({
"list_id": self.list.id,
"list_ids": [(4, self.list.id, False)],
"partner_id": self.partners[0].id,
})
contact1 = Contact.search([
("list_id", "=", self.list.id),
("list_ids", "in", [self.list.id]),
], limit=1)
with self.assertRaises(ValidationError):
contact1.name = "other"
@ -82,7 +81,7 @@ class DynamicListCase(common.SavepointCase):
self.list.dynamic = False
# Now the contact is created without exception
Contact.create({
"list_id": self.list.id,
"list_ids": [(4, self.list.id, False)],
"email": "test@example.com",
})
# Contacts can now be changed

5
mass_mailing_list_dynamic/views/mail_mass_mailing_list_view.xml

@ -54,7 +54,7 @@
<i class="fa fa-info-circle"/> You cannot make manual editions of contacts in fully synchronized lists.
</div>
</group>
<group colspan="4"
<group colspan="2"
attrs="{'invisible': [('dynamic', '=', False)]}">
<field
name="sync_domain"
@ -62,14 +62,15 @@
options='{"model": "res.partner"}'
/>
</group>
<group attrs="{'invisible': [('dynamic', '=', False)]}">
<button
name="%(action_mail_mass_mailing_load_filter)d"
type="action"
string="Load filter"
icon="fa-filter"
colspan="1"
/>
</group>
</group>
</xpath>
<field name="contact_nbr" position="attributes">
<attribute name="attrs">

1
mass_mailing_list_dynamic/wizards/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import mail_mass_mailing_load_filter

1
mass_mailing_list_dynamic/wizards/mail_mass_mailing_load_filter.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

Loading…
Cancel
Save