From f7862cd2b5cfd333688b219a64034e24f7d2e5a1 Mon Sep 17 00:00:00 2001 From: xO-Tx Date: Mon, 15 Jun 2020 07:49:43 +0000 Subject: [PATCH] [IMP] mass_mailing[_sms]: update subject and allow emoji support for sms content PURPOSE Subject field on mailing has not the same use in email marketing (subject of emails) and in SMS maketing (used internally as there is no subject in SMS). Purpose of this commit is to improve mailing form view to better distinguish email and SMS flows. SPECIFICATIONS This commit changes helper for mailing subject and update its label according to mailing_type (mail or sms), as well as the sms content field to enable emoji support in mailing subjects. This is done through a fake sms_subject field that is a text without emojis while standard subject allows emojis. Helpers depends on the displayed field. Override CRUD to synchronize sms_subject on subject to have only one field used to store data. Also allow emojis in SMS content, suing the enable_emojis option. LINKS Task ID-2224393 PR #49096 --- addons/mass_mailing/models/mailing.py | 2 +- .../models/mailing_mailing.py | 20 +++++++++++++++++++ .../views/mailing_mailing_views.xml | 12 ++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/addons/mass_mailing/models/mailing.py b/addons/mass_mailing/models/mailing.py index 86b6714260e..15b38a1d1d2 100644 --- a/addons/mass_mailing/models/mailing.py +++ b/addons/mass_mailing/models/mailing.py @@ -66,7 +66,7 @@ class MassMailing(models.Model): return False active = fields.Boolean(default=True, tracking=True) - subject = fields.Char('Subject', help='Subject of emails to send', required=True, translate=True) + subject = fields.Char('Subject', help='Subject of your Mailing', required=True, translate=True) email_from = fields.Char(string='Send From', required=True, default=lambda self: self.env.user.email_formatted) sent_date = fields.Datetime(string='Sent Date', copy=False) diff --git a/addons/mass_mailing_sms/models/mailing_mailing.py b/addons/mass_mailing_sms/models/mailing_mailing.py index cd0e6060f6f..ee1c11e20db 100644 --- a/addons/mass_mailing_sms/models/mailing_mailing.py +++ b/addons/mass_mailing_sms/models/mailing_mailing.py @@ -24,6 +24,15 @@ class Mailing(models.Model): mailing_type = fields.Selection(selection_add=[ ('sms', 'SMS') ], ondelete={'sms': 'set default'}) + + # 'sms_subject' added to override 'subject' field (string attribute should be labelled "Title" when mailing_type == 'sms'). + # 'sms_subject' should have the same helper as 'subject' field when 'mass_mailing_sms' installed. + # otherwise 'sms_subject' will get the old helper from 'mass_mailing' module. + # overriding 'subject' field helper in this model is not working, since the helper will keep the new value + # even when 'mass_mailing_sms' removed (see 'mailing_mailing_view_form_sms' for more details). + sms_subject = fields.Char('Title', help='For an Email, Subject your Recipients will see in their inbox.\n' + 'For an SMS Text Message, internal Title of the Message.', + related='subject', translate=True, readonly=False) # sms options body_plaintext = fields.Text('SMS Body', compute='_compute_body_plaintext', store=True, readonly=False) sms_template_id = fields.Many2one('sms.template', string='SMS Template', ondelete='set null') @@ -74,6 +83,17 @@ class Mailing(models.Model): mail.sms_has_unregistered_account = trace_dict[mail.id]['sms_acc'] + # -------------------------------------------------- + # ORM OVERRIDES + # -------------------------------------------------- + + @api.model + def create(self, values): + # Get subject from "sms_subject" field when SMS installed (used to build the name of record in the super 'create' method) + if values.get('mailing_type') == 'sms' and values.get('sms_subject'): + values['subject'] = values['sms_subject'] + return super(Mailing, self).create(values) + # -------------------------------------------------- # BUSINESS / VIEWS ACTIONS # -------------------------------------------------- diff --git a/addons/mass_mailing_sms/views/mailing_mailing_views.xml b/addons/mass_mailing_sms/views/mailing_mailing_views.xml index 9b6244853ab..570198797b9 100644 --- a/addons/mass_mailing_sms/views/mailing_mailing_views.xml +++ b/addons/mass_mailing_sms/views/mailing_mailing_views.xml @@ -93,12 +93,22 @@ {'invisible': ['|',('mailing_type', '!=', 'mail'),('state', 'in', ('draft','test'))]} + + {'invisible': [('mailing_type', '!=', 'mail')], 'readonly': [('state', 'in', ('sending', 'done'))], 'required': [('mailing_type', '=', 'mail')]} + + For an Email, Subject your Recipients will see in their inbox. + For an SMS Text Message, internal Title of the Message. + + + + {'invisible': [('mailing_type', '!=', 'mail')]} - +