From 542af01df476b721e3ff9cf7fd88febd37c88c16 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 20 Mar 2018 11:57:18 +0100 Subject: [PATCH] [IMP] mass_mailing_list_dynamic: make user aware of list change - Adds is_synced field to track whether a dynamic list has unsynced changes or not so the user is aware that the definitive number of contacts is yet to be determined. - It fixes an issue that made impossible deleting a res.partner filter when a list had use it to filter contacts. - It also shows only the filters available for the user (shared and belonging to self). --- mass_mailing_list_dynamic/__manifest__.py | 2 +- .../models/mail_mass_mailing_list.py | 12 ++++++++++- .../tests/test_dynamic_lists.py | 11 ++++++++++ .../views/mail_mass_mailing_list_view.xml | 20 +++++++++++++++++++ .../wizards/mail_mass_mailing_load_filter.py | 4 +++- 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/mass_mailing_list_dynamic/__manifest__.py b/mass_mailing_list_dynamic/__manifest__.py index 80371977..6e0e2439 100644 --- a/mass_mailing_list_dynamic/__manifest__.py +++ b/mass_mailing_list_dynamic/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Dynamic Mass Mailing Lists", "summary": "Mass mailing lists that get autopopulated", - "version": "10.0.1.1.1", + "version": "10.0.1.2.0", "category": "Marketing", "website": "https://github.com/OCA/social", "author": "Tecnativa, Odoo Community Association (OCA)", diff --git a/mass_mailing_list_dynamic/models/mail_mass_mailing_list.py b/mass_mailing_list_dynamic/models/mail_mass_mailing_list.py index 93a4fe67..47be1b65 100644 --- a/mass_mailing_list_dynamic/models/mail_mass_mailing_list.py +++ b/mass_mailing_list_dynamic/models/mail_mass_mailing_list.py @@ -2,7 +2,7 @@ # Copyright 2017 Tecnativa - Jairo Llopis # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import fields, models +from odoo import api, fields, models from odoo.tools import safe_eval @@ -29,6 +29,10 @@ class MassMailingList(models.Model): required=True, help="Filter partners to sync in this list", ) + is_synced = fields.Boolean( + help="Helper field to make the user aware of unsynced changes", + default=True, + ) def action_sync(self): """Sync contacts in dynamic lists.""" @@ -55,5 +59,11 @@ class MassMailingList(models.Model): "list_id": one.id, "partner_id": partner.id, }) + one.is_synced = True # Invalidate cached contact count self.invalidate_cache(["contact_nbr"], dynamic.ids) + + @api.onchange("dynamic", "sync_method", "sync_domain") + def _onchange_dynamic(self): + if self.dynamic: + self.is_synced = False diff --git a/mass_mailing_list_dynamic/tests/test_dynamic_lists.py b/mass_mailing_list_dynamic/tests/test_dynamic_lists.py index ded412a6..eb781a59 100644 --- a/mass_mailing_list_dynamic/tests/test_dynamic_lists.py +++ b/mass_mailing_list_dynamic/tests/test_dynamic_lists.py @@ -126,3 +126,14 @@ class DynamicListCase(common.SavepointCase): self.partners[:1].write({ 'email': 'test_mass_mailing_list_dynamic@example.org', }) + + def test_is_synced(self): + self.list.dynamic = False + self.list._onchange_dynamic() + # It shouldn't change when list is reversed to normal + self.assertTrue(self.list.is_synced) + self.list.dynamic = True + self.list._onchange_dynamic() + self.assertFalse(self.list.is_synced) + self.list.action_sync() + self.assertTrue(self.list.is_synced) diff --git a/mass_mailing_list_dynamic/views/mail_mass_mailing_list_view.xml b/mass_mailing_list_dynamic/views/mail_mass_mailing_list_view.xml index 10046ef4..79dc523f 100644 --- a/mass_mailing_list_dynamic/views/mail_mass_mailing_list_view.xml +++ b/mass_mailing_list_dynamic/views/mail_mass_mailing_list_view.xml @@ -15,6 +15,7 @@ +