diff options
| author | Tiffany Chang (tic) <tic@odoo.com> | 2020-01-14 10:15:45 +0000 |
|---|---|---|
| committer | Tiffany Chang (tic) <tic@odoo.com> | 2020-01-21 12:43:48 +0000 |
| commit | dced1d2f701b69725a998fce48fd1df3a6be11a6 (patch) | |
| tree | fc09ec2fe254a572493e6793744b1310db960490 | |
| parent | b786adf2e922dce30987acfa0172c3d1f162cf59 (diff) | |
[IMP] mass_mailing_sms: Add mailing_type domain activity restriction
Restrict the displayed activities when clicking on "Email Marketing"
and "SMS Marketing" modules in the activity systray. Due to their
activities being linked to the same model, we need to distinguish which
activities belong to which module based on their assigned mailing_type
value. Without this domain restriction, users can still filter based on
mailing_type, but it is much less intuitive this way due to them being
separate apps.
Task: 2169498
| -rw-r--r-- | addons/mass_mailing_sms/models/res_users.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/addons/mass_mailing_sms/models/res_users.py b/addons/mass_mailing_sms/models/res_users.py index cc095e7e397..8c23887c537 100644 --- a/addons/mass_mailing_sms/models/res_users.py +++ b/addons/mass_mailing_sms/models/res_users.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import json + from odoo import api, fields, models, modules, _ @@ -18,7 +20,7 @@ class Users(models.Model): for activity in activities: if activity.get('model') == 'mailing.mailing': activities.remove(activity) - query = """SELECT m.mailing_type, count(*), act.res_model as model, + query = """SELECT m.mailing_type, count(*), act.res_model as model, act.res_id, CASE WHEN %(today)s::date - act.date_deadline::date = 0 Then 'today' WHEN %(today)s::date - act.date_deadline::date > 0 Then 'overdue' @@ -27,7 +29,7 @@ class Users(models.Model): FROM mail_activity AS act JOIN mailing_mailing AS m ON act.res_id = m.id WHERE act.res_model = 'mailing.mailing' AND act.user_id = %(user_id)s - GROUP BY m.mailing_type, states, act.res_model; + GROUP BY m.mailing_type, states, act.res_model, act.res_id; """ self.env.cr.execute(query, { 'today': fields.Date.context_today(self), @@ -45,13 +47,16 @@ class Users(models.Model): module = 'mass_mailing' name = _('Email Marketing') icon = module and modules.module.get_module_icon(module) + res_ids = set() user_activities[act['mailing_type']] = { 'name': name, 'model': 'mailing.mailing', 'type': 'activity', 'icon': icon, 'total_count': 0, 'today_count': 0, 'overdue_count': 0, 'planned_count': 0, + 'res_ids': res_ids, } + user_activities[act['mailing_type']]['res_ids'].add(act['res_id']) user_activities[act['mailing_type']]['%s_count' % act['states']] += act['count'] if act['states'] in ('today', 'overdue'): user_activities[act['mailing_type']]['total_count'] += act['count'] @@ -59,8 +64,8 @@ class Users(models.Model): for mailing_type in user_activities.keys(): user_activities[mailing_type].update({ 'actions': [{'icon': 'fa-clock-o', 'name': 'Summary',}], + 'domain': json.dumps([['activity_ids.res_id', 'in', list(user_activities[mailing_type]['res_ids'])]]) }) - activities.extend(list(user_activities.values())) break |
