diff options
| author | xO-Tx <mou@odoo.com> | 2020-06-15 07:49:43 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-08-11 14:38:33 +0000 |
| commit | f7862cd2b5cfd333688b219a64034e24f7d2e5a1 (patch) | |
| tree | 4860e137aaa75e2e03a2ad778bf08a2f7e16cb52 | |
| parent | 6e8f4ff3ead93ad1e9294b0ebed8d60e4e4bf1ce (diff) | |
[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
| -rw-r--r-- | addons/mass_mailing/models/mailing.py | 2 | ||||
| -rw-r--r-- | addons/mass_mailing_sms/models/mailing_mailing.py | 20 | ||||
| -rw-r--r-- | addons/mass_mailing_sms/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') @@ -75,6 +84,17 @@ class Mailing(models.Model): # -------------------------------------------------- + # 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 @@ <attribute name="attrs">{'invisible': ['|',('mailing_type', '!=', 'mail'),('state', 'in', ('draft','test'))]}</attribute> </xpath> <!-- Form --> + <xpath expr="//field[@name='subject']" position="attributes"> + <attribute name="attrs">{'invisible': [('mailing_type', '!=', 'mail')], 'readonly': [('state', 'in', ('sending', 'done'))], 'required': [('mailing_type', '=', 'mail')]}</attribute> + <!-- overrided in xml view to prevent remaining helper changes (on mass_mailing module) when mass_mailing_sms uninstalled--> + <attribute name="help">For an Email, Subject your Recipients will see in their inbox. + For an SMS Text Message, internal Title of the Message.</attribute> + </xpath> + <xpath expr="//field[@name='subject']" position="after"> + <field name="sms_subject" string="Title" attrs="{'invisible': [('mailing_type', '!=', 'sms')], 'readonly': [('state', 'in', ('sending', 'done'))], 'required': [('mailing_type', '=', 'sms')]}"/> + </xpath> <xpath expr="//page[@name='mail_body']" position="attributes"> <attribute name="attrs">{'invisible': [('mailing_type', '!=', 'mail')]}</attribute> </xpath> <xpath expr="//page[@name='mail_body']" position="after"> <page string="SMS Content" name="sms_body" attrs="{'invisible': [('mailing_type', '!=', 'sms')]}"> - <field name="body_plaintext" widget="sms_widget" attrs="{'required': [('mailing_type', '=', 'sms')]}"/> + <field name="body_plaintext" widget="sms_widget" attrs="{'required': [('mailing_type', '=', 'sms')]}" + options='{"enable_emojis": True}'/> <group> <field name="sms_force_send" invisible="1"/> </group> |
