From e542cca69ef4ce1b5c24b78839ddb1baab64df1c Mon Sep 17 00:00:00 2001 From: dht-odoo Date: Wed, 19 Jan 2022 11:07:59 +0530 Subject: [PATCH 1/3] [IMP] mass_mailing: improve mailing form view design - Before this commit, it could happen sometime that the time for which mailing was schedules has passed, but user was still getting the same ribbon that mail was scheduled for a particular time (which is a bit confusing). And also in the case of schedule_type equals to now we are displaying the next_departure datetime in ribbon. This commit improves the behavior and in such cases, displays a new ribbon message saying "This mailing will be sent as soon as possible." and has as refresh button next to it, which reloads the page. Once the mailing is sent, this ribbon will also be hidden. For that, we introduce a new compute boolean `is_past_departure` which will be true only if the scheduled time is in past and the mailing is still in queue. And for the case scedule_type equals to now we are displaying a new message on ribbon with refresh button. - Re-arranges the model container part of the form view of a mailing in order to utilize the horizontal space. It moves domain next to the model / filter related fields so that everything is in a single row, and thus reducing vertical space. TaskId-2702607 Part-of: odoo/odoo#82107 --- addons/mass_mailing/models/mailing.py | 12 +++++ .../static/src/scss/mass_mailing.scss | 25 +++++++++ .../views/mailing_mailing_views.xml | 51 ++++++++++++++----- 3 files changed, 75 insertions(+), 13 deletions(-) diff --git a/addons/mass_mailing/models/mailing.py b/addons/mass_mailing/models/mailing.py index 33a38ab5b0b..938d493b880 100644 --- a/addons/mass_mailing/models/mailing.py +++ b/addons/mass_mailing/models/mailing.py @@ -224,6 +224,7 @@ class MassMailing(models.Model): clicks_ratio = fields.Float(compute="_compute_clicks_ratio", string="Number of Clicks") next_departure = fields.Datetime(compute="_compute_next_departure", string='Scheduled date') # UX + next_departure_is_past = fields.Boolean(compute="_compute_next_departure") warning_message = fields.Char( 'Warning Message', compute='_compute_warning_message', help='Warning message displayed in the mailing form view') @@ -336,6 +337,7 @@ class MassMailing(models.Model): row['bounced_ratio'] = float_round(100.0 * row['bounced'] / total, precision_digits=2) self.browse(row.pop('mailing_id')).update(row) + @api.depends('schedule_date', 'state') def _compute_next_departure(self): # Schedule_date should only be False if schedule_type = "now" or # mass_mailing is canceled. @@ -344,12 +346,19 @@ class MassMailing(models.Model): # execute this based on the cron.trigger's call_at which should # be now() when clicking "Send" or schedule_date if scheduled + # If the departure time has passed but mailing is still in queue, this compute field + # will be used to display warning with reload button on a mailing form view. for mass_mailing in self: if mass_mailing.schedule_date: # max in case the user schedules a date in the past mass_mailing.next_departure = max(mass_mailing.schedule_date, fields.datetime.now()) else: mass_mailing.next_departure = fields.datetime.now() + past = self.filtered( + lambda mailing: mailing.state == 'in_queue' and mailing.next_departure < fields.Datetime.now() + ) + past.next_departure_is_past = True + (self - past).next_departure_is_past = False @api.depends('email_from', 'mail_server_id') def _compute_warning_message(self): @@ -621,6 +630,9 @@ class MassMailing(models.Model): self.write({'schedule_type': 'now'}) return self.action_put_in_queue() + def action_reload(self): + pass + def action_schedule(self): self.ensure_one() if self.schedule_date and self.schedule_date > fields.Datetime.now(): diff --git a/addons/mass_mailing/static/src/scss/mass_mailing.scss b/addons/mass_mailing/static/src/scss/mass_mailing.scss index 5a05a8b3c01..9758e674b18 100644 --- a/addons/mass_mailing/static/src/scss/mass_mailing.scss +++ b/addons/mass_mailing/static/src/scss/mass_mailing.scss @@ -54,6 +54,23 @@ color: $o-main-favorite-color; } } + // Align the model / domain container with subject field in large devices + // and provide better tap area to the filter + @include media-breakpoint-up(md) { + div[name="mailing_model_id_container"] { + width: 96%; + } + .o_mailing_filter_width { + max-width: 25%; + } + .o_readonly_modifier.o_mailing_filter_readonly_width , + &.o_form_readonly .o_mailing_filter_readonly_width { + max-width: 100%; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + } } .o_xxs_form_view.o_mass_mailing_mailing_form { @@ -176,3 +193,11 @@ min-height: 55vh; } } + +.o_mass_mailing_form_full_width.o_form_editable { + .o_domain_selector.o_read_mode { + .o_domain_tree_header.oe_edit_only { + display: none; + } + } +} diff --git a/addons/mass_mailing/views/mailing_mailing_views.xml b/addons/mass_mailing/views/mailing_mailing_views.xml index 1bbf54e3862..a6e954b0dbd 100644 --- a/addons/mass_mailing/views/mailing_mailing_views.xml +++ b/addons/mass_mailing/views/mailing_mailing_views.xml @@ -119,11 +119,27 @@ +
- + This mailing is scheduled for . + + + This mailing will be sent as soon as possible. + + + + + + This mailing will be sent as soon as possible. + +
@@ -194,12 +210,12 @@
-
-
+
+
-
+
-
- -
@@ -400,7 +414,7 @@ state != 'in_queue' - scheduled == 0 + not scheduled or next_departure_is_past email(s) scheduled for @@ -410,8 +424,16 @@ scheduled != 0 + + scheduled + + + scheduled + + + @@ -451,6 +473,9 @@
+ + col-md-7 + From f7667bdd282e5074fa30fea3cea37167deaaac78 Mon Sep 17 00:00:00 2001 From: dht-odoo Date: Thu, 30 Dec 2021 11:50:36 +0530 Subject: [PATCH 2/3] [IMP] mass_mailing: add 'create_date' in subscription list view This commit will add create_date field in view to display it as 'Subscription Date' to the user so that concerned people can know when did the contact subscribed into a mailing list. Here, now when we will import contacts in mailing.contacts we are linking the mailing_list in subscription_list_ids using Command to get the values of create_date. TaskId-2702607 Part-of: odoo/odoo#82107 --- addons/mass_mailing/tests/test_mailing_list.py | 1 + addons/mass_mailing/views/mailing_contact_views.xml | 1 + addons/mass_mailing/views/mailing_subscription_views.xml | 2 ++ addons/mass_mailing/wizard/mailing_contact_import.py | 7 +++++-- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/mass_mailing/tests/test_mailing_list.py b/addons/mass_mailing/tests/test_mailing_list.py index 0630e8cb3ec..58c7f4f31c0 100644 --- a/addons/mass_mailing/tests/test_mailing_list.py +++ b/addons/mass_mailing/tests/test_mailing_list.py @@ -243,6 +243,7 @@ class TestMailingContactImport(MassMailCommon): # Test that the context key "default_list_ids" is ignored (because we manually set list_ids) contact_import.with_context(default_list_ids=(first_list | second_list).ids).action_import() + self.env['mailing.list'].invalidate_model(['contact_ids']) # Check the contact of the first mailing list contacts = [ (contact.name, contact.email) diff --git a/addons/mass_mailing/views/mailing_contact_views.xml b/addons/mass_mailing/views/mailing_contact_views.xml index addad64f748..95b2dbf2b14 100644 --- a/addons/mass_mailing/views/mailing_contact_views.xml +++ b/addons/mass_mailing/views/mailing_contact_views.xml @@ -150,6 +150,7 @@ + diff --git a/addons/mass_mailing/views/mailing_subscription_views.xml b/addons/mass_mailing/views/mailing_subscription_views.xml index 9c58dcf6b2f..a5dac064f5a 100644 --- a/addons/mass_mailing/views/mailing_subscription_views.xml +++ b/addons/mass_mailing/views/mailing_subscription_views.xml @@ -16,6 +16,7 @@ aria-label="Blacklisted" invisible="not is_blacklisted" groups="base.group_user">
+ @@ -32,6 +33,7 @@ + diff --git a/addons/mass_mailing/wizard/mailing_contact_import.py b/addons/mass_mailing/wizard/mailing_contact_import.py index 33693f4fbda..182b7fa56a8 100644 --- a/addons/mass_mailing/wizard/mailing_contact_import.py +++ b/addons/mass_mailing/wizard/mailing_contact_import.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models, tools, _ +from odoo import fields, models, tools, Command, _ from odoo.tools.misc import clean_context @@ -63,7 +63,10 @@ class MailingContactImport(models.TransientModel): if email not in existing_contacts: unique_contacts[email] = { 'name': name, - 'list_ids': self.mailing_list_ids.ids, + 'subscription_ids': [ + Command.create({'list_id': mailing_list_id.id}) + for mailing_list_id in self.mailing_list_ids + ], } if not unique_contacts: From c00ea04837e07aa63dd9c4e6d8c538ff76d4a420 Mon Sep 17 00:00:00 2001 From: dht-odoo Date: Wed, 29 Dec 2021 18:38:46 +0530 Subject: [PATCH 3/3] [IMP] mass_mailing(_sms): add a button to send mailing & sms from mailing list This commit introduces a button "Send New Mailing" & "Send New SMS" on the mailing list so that one can direct send mailing & sms from a mailing list. The current list will be set as default one in the mailing. TaskId-2702607 Part-of: odoo/odoo#82107 --- addons/mass_mailing/models/mailing_list.py | 2 ++ .../mass_mailing/tests/test_mailing_list.py | 13 +++++++++ .../mass_mailing/views/mailing_list_views.xml | 4 +++ .../mass_mailing_sms/models/mailing_list.py | 16 +++++++++++ addons/mass_mailing_sms/tests/__init__.py | 1 + .../tests/test_mailing_list.py | 27 +++++++++++++++++++ .../views/mailing_list_views.xml | 12 +++++++++ 7 files changed, 75 insertions(+) create mode 100644 addons/mass_mailing_sms/tests/test_mailing_list.py diff --git a/addons/mass_mailing/models/mailing_list.py b/addons/mass_mailing/models/mailing_list.py index c8ca4e4743b..ce995d2c1ed 100644 --- a/addons/mass_mailing/models/mailing_list.py +++ b/addons/mass_mailing/models/mailing_list.py @@ -160,6 +160,8 @@ class MassMailingList(models.Model): 'context': { **self.env.context, 'default_contact_list_ids': self.ids, + 'default_mailing_type': 'mail', + 'default_model_id': self.env['ir.model']._get_id('mailing.list'), }, 'target': 'current', 'view_type': 'form', diff --git a/addons/mass_mailing/tests/test_mailing_list.py b/addons/mass_mailing/tests/test_mailing_list.py index 58c7f4f31c0..b9cc685d51d 100644 --- a/addons/mass_mailing/tests/test_mailing_list.py +++ b/addons/mass_mailing/tests/test_mailing_list.py @@ -119,6 +119,19 @@ class TestMailingListMerge(MassMailCommon): self.assertEqual(contact.subscription_ids[0].opt_out_datetime, datetime(2022, 1, 1, 12, 0, 0)) self.assertFalse(contact.subscription_ids[1].opt_out_datetime) + @users('user_marketing') + def test_mailing_list_action_send_mailing(self): + mailing_ctx = self.mailing_list_1.action_send_mailing().get('context', {}) + form = Form(self.env['mailing.mailing'].with_context(mailing_ctx)) + form.subject = 'Test Mail' + mailing = form.save() + # Check that mailing model and mailing list are set properly + self.assertEqual( + mailing.mailing_model_id, self.env['ir.model']._get('mailing.list'), + 'Should have correct mailing model set') + self.assertEqual(mailing.contact_list_ids, self.mailing_list_1, 'Should have correct mailing list set') + self.assertEqual(mailing.mailing_type, 'mail', 'Should have correct mailing_type') + @users('user_marketing') def test_mailing_list_contact_copy_in_context_of_mailing_list(self): MailingContact = self.env['mailing.contact'] diff --git a/addons/mass_mailing/views/mailing_list_views.xml b/addons/mass_mailing/views/mailing_list_views.xml index 30f24550672..94d387137ee 100644 --- a/addons/mass_mailing/views/mailing_list_views.xml +++ b/addons/mass_mailing/views/mailing_list_views.xml @@ -39,6 +39,10 @@ mailing.list
+
+