From 1c614e34dc4d8fef95970aa781f56f4f0c532f1e Mon Sep 17 00:00:00 2001 From: qmo-odoo Date: Mon, 16 Sep 2019 11:38:06 +0000 Subject: [PATCH] [IMP] mass_mailing: hide name field on the mailing and always display subject This commit hides the field "name" of the mailing.mailing model. Instead of having both fields "name" and "subject" on the form, "name" will only be visible in debug mode leaving only "subject" to be visible for other users. Indeed name is a more technical field used to create and find UTM source record back while subject is the real business field. This change implies that the name will now be set by default in the create method so that the UTMs keeps working as they were. The name will be constructed as follow: "subject create_date". If the admin decides to set the name himself, the name will not be set by default. Field is set in debug mode to allow its edition. In mass mailing sms subject field is made visible. The name field being only visible in debug mode now, the subject field had to be made visible in the mailing form of the mass_mailing_sms module. LINKS Task ID 2072130 (hide name on mass mailing) PR: #36935 --- addons/mass_mailing/models/mailing.py | 15 +++------------ .../mass_mailing/views/mailing_mailing_views.xml | 14 +++++++------- addons/mass_mailing_sms/data/mailing_demo.xml | 4 ++-- .../views/mailing_mailing_views.xml | 6 ------ addons/test_mail_full/tests/test_sms_sms.py | 2 +- 5 files changed, 13 insertions(+), 28 deletions(-) diff --git a/addons/mass_mailing/models/mailing.py b/addons/mass_mailing/models/mailing.py index 6beb68ad7e9..8b5d9d18a49 100644 --- a/addons/mass_mailing/models/mailing.py +++ b/addons/mass_mailing/models/mailing.py @@ -10,6 +10,7 @@ import re import threading from ast import literal_eval from base64 import b64encode +from datetime import datetime from odoo import api, fields, models, tools, _, SUPERUSER_ID from odoo.exceptions import UserError @@ -229,24 +230,14 @@ class MassMailing(models.Model): if self.mailing_type == 'mail' and not self.medium_id: self.medium_id = self.env.ref('utm.utm_medium_email').id - @api.onchange('subject') - def _onchange_subject(self): - if self.subject and not self.name: - self.name = self.subject - - @api.onchange('name') - def _onchange_name(self): - if self.name and not self.subject: - self.subject = self.name - # ------------------------------------------------------ # ORM # ------------------------------------------------------ @api.model def create(self, values): - if values.get('name') and not values.get('subject'): - values['subject'] = values['name'] + if values.get('subject') and not values.get('name'): + values['name'] = "%s %s" % (values['subject'], datetime.strftime(fields.datetime.now(), tools.DEFAULT_SERVER_DATETIME_FORMAT)) if values.get('body_html'): values['body_html'] = self._convert_inline_images_to_urls(values['body_html']) if 'medium_id' not in values and values.get('mailing_type', 'mail') == 'mail': diff --git a/addons/mass_mailing/views/mailing_mailing_views.xml b/addons/mass_mailing/views/mailing_mailing_views.xml index ba16528d602..c03fbddf526 100644 --- a/addons/mass_mailing/views/mailing_mailing_views.xml +++ b/addons/mass_mailing/views/mailing_mailing_views.xml @@ -29,7 +29,7 @@ 10 - + @@ -134,7 +134,7 @@ - + @@ -142,7 +142,7 @@
-
@@ -163,7 +163,7 @@ 'invisible': [('mailing_model_name', '=', 'mailing.list')], 'readonly': [('state', 'in', ('sending', 'done'))] }"> - +
@@ -197,7 +197,7 @@ }"/> @@ -229,7 +229,7 @@ attrs="{'readonly': [('state', 'in', ('sending', 'done'))]}"/>