[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
This commit is contained in:
xO-Tx
2020-08-11 14:38:33 +00:00
committed by Thibault Delavallée
parent 6e8f4ff3ea
commit f7862cd2b5
3 changed files with 32 additions and 2 deletions
+1 -1
View File
@@ -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)
@@ -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
# --------------------------------------------------
@@ -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>