mirror of https://github.com/OCA/social.git
[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).pull/399/head
parent
3edb0ec21c
commit
e42d13490b
mass_mailing_list_dynamic
|
@ -5,7 +5,7 @@
|
||||||
{
|
{
|
||||||
"name": "Dynamic Mass Mailing Lists",
|
"name": "Dynamic Mass Mailing Lists",
|
||||||
"summary": "Mass mailing lists that get autopopulated",
|
"summary": "Mass mailing lists that get autopopulated",
|
||||||
"version": "10.0.1.1.1",
|
"version": "10.0.1.2.0",
|
||||||
"category": "Marketing",
|
"category": "Marketing",
|
||||||
"website": "https://github.com/OCA/social",
|
"website": "https://github.com/OCA/social",
|
||||||
"author": "Tecnativa, Odoo Community Association (OCA)",
|
"author": "Tecnativa, Odoo Community Association (OCA)",
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# Copyright 2017 Tecnativa - Jairo Llopis
|
# Copyright 2017 Tecnativa - Jairo Llopis
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# 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
|
from odoo.tools import safe_eval
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,6 +29,10 @@ class MassMailingList(models.Model):
|
||||||
required=True,
|
required=True,
|
||||||
help="Filter partners to sync in this list",
|
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):
|
def action_sync(self):
|
||||||
"""Sync contacts in dynamic lists."""
|
"""Sync contacts in dynamic lists."""
|
||||||
|
@ -55,5 +59,11 @@ class MassMailingList(models.Model):
|
||||||
"list_id": one.id,
|
"list_id": one.id,
|
||||||
"partner_id": partner.id,
|
"partner_id": partner.id,
|
||||||
})
|
})
|
||||||
|
one.is_synced = True
|
||||||
# Invalidate cached contact count
|
# Invalidate cached contact count
|
||||||
self.invalidate_cache(["contact_nbr"], dynamic.ids)
|
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
|
||||||
|
|
|
@ -126,3 +126,14 @@ class DynamicListCase(common.SavepointCase):
|
||||||
self.partners[:1].write({
|
self.partners[:1].write({
|
||||||
'email': 'test_mass_mailing_list_dynamic@example.org',
|
'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)
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
<field
|
<field
|
||||||
name="dynamic"
|
name="dynamic"
|
||||||
/>
|
/>
|
||||||
|
<field name="is_synced" invisible="1"/>
|
||||||
</group>
|
</group>
|
||||||
<group attrs="{'invisible': [('dynamic', '=', False)]}">
|
<group attrs="{'invisible': [('dynamic', '=', False)]}">
|
||||||
<label for="sync_method"/>
|
<label for="sync_method"/>
|
||||||
|
@ -22,11 +23,20 @@
|
||||||
<field
|
<field
|
||||||
name="sync_method"
|
name="sync_method"
|
||||||
/>
|
/>
|
||||||
|
<button
|
||||||
|
name="action_sync"
|
||||||
|
type="object"
|
||||||
|
string="Sync now"
|
||||||
|
icon="fa-exclamation-triangle"
|
||||||
|
class="btn-danger"
|
||||||
|
attrs="{'invisible': [('is_synced', '=', True)]}"
|
||||||
|
/>
|
||||||
<button
|
<button
|
||||||
name="action_sync"
|
name="action_sync"
|
||||||
type="object"
|
type="object"
|
||||||
string="Sync now"
|
string="Sync now"
|
||||||
icon="fa-refresh"
|
icon="fa-refresh"
|
||||||
|
attrs="{'invisible': [('is_synced', '=', False)]}"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</group>
|
</group>
|
||||||
|
@ -61,6 +71,16 @@
|
||||||
/>
|
/>
|
||||||
</group>
|
</group>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
<field name="contact_nbr" position="attributes">
|
||||||
|
<attribute name="attrs">
|
||||||
|
{'invisible': [('is_synced', '=', False)]}
|
||||||
|
</attribute>
|
||||||
|
</field>
|
||||||
|
<field name="contact_nbr" position="after">
|
||||||
|
<span attrs="{'invisible': [('is_synced', '=', True)]}">
|
||||||
|
<strong>???</strong>
|
||||||
|
</span>
|
||||||
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,9 @@ class MassMailingLoadFilter(models.TransientModel):
|
||||||
comodel_name='ir.filters',
|
comodel_name='ir.filters',
|
||||||
string="Filter to load",
|
string="Filter to load",
|
||||||
required=True,
|
required=True,
|
||||||
domain=[('model_id', '=', 'res.partner')],
|
domain="[('model_id', '=', 'res.partner'), '|', "
|
||||||
|
"('user_id', '=', uid), ('user_id','=',False)]",
|
||||||
|
ondelete='cascade',
|
||||||
)
|
)
|
||||||
|
|
||||||
def load_filter(self):
|
def load_filter(self):
|
||||||
|
|
Loading…
Reference in New Issue