[MERGE] mass_mailing: improve action buttons and ease mass mailing scheduling
Purpose of this merge is to clearly distinguish sending a mass mailing from scheduling it to a future date. Currently both options are a bit mixed and not obvious. Now buttons are separated. Scheduling opens a small wizard allowing to choose the date. Some computation of sent and scheduled date are also fixed to be cleaner. This merge is related to task ID 46932. Closes #24465.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
'wizard/mail_compose_message_views.xml',
|
||||
'wizard/mass_mailing_list_merge_views.xml',
|
||||
'wizard/test_mailing_views.xml',
|
||||
'wizard/mass_mailing_schedule_date_views.xml',
|
||||
'views/mass_mailing_report_views.xml',
|
||||
'views/mass_mailing_stats_views.xml',
|
||||
'views/link_tracker_views.xml',
|
||||
|
||||
@@ -637,13 +637,20 @@ class MassMailing(models.Model):
|
||||
'context': ctx,
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def action_schedule_date(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref('mass_mailing.mass_mailing_schedule_date_action').read()[0]
|
||||
action['context'] = dict(self.env.context, default_mass_mailing_id=self.id)
|
||||
return action
|
||||
|
||||
@api.multi
|
||||
def put_in_queue(self):
|
||||
self.write({'sent_date': fields.Datetime.now(), 'state': 'in_queue'})
|
||||
self.write({'state': 'in_queue'})
|
||||
|
||||
@api.multi
|
||||
def cancel_mass_mailing(self):
|
||||
self.write({'state': 'draft'})
|
||||
self.write({'state': 'draft', 'schedule_date': False})
|
||||
|
||||
@api.multi
|
||||
def retry_failed_mail(self):
|
||||
@@ -784,7 +791,7 @@ class MassMailing(models.Model):
|
||||
# auto-commit except in testing mode
|
||||
auto_commit = not getattr(threading.currentThread(), 'testing', False)
|
||||
composer.send_mail(auto_commit=auto_commit)
|
||||
mailing.state = 'done'
|
||||
mailing.write({'state': 'done', 'sent_date': fields.Datetime.now()})
|
||||
return True
|
||||
|
||||
def convert_links(self):
|
||||
@@ -818,4 +825,4 @@ class MassMailing(models.Model):
|
||||
mass_mailing.state = 'sending'
|
||||
mass_mailing.send_mail()
|
||||
else:
|
||||
mass_mailing.state = 'done'
|
||||
mass_mailing.write({'state': 'done', 'sent_date': fields.Datetime.now()})
|
||||
|
||||
@@ -411,10 +411,11 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Mailing">
|
||||
<header style="min-height:31px;">
|
||||
<button name="action_test_mailing" type="object" class="oe_highlight" string="Test Mailing"/>
|
||||
<button name="put_in_queue" type="object" attrs="{'invisible': ['|', ('state', 'in', ('in_queue', 'done'))]}" class="oe_highlight" string="Send to All"
|
||||
<button name="put_in_queue" type="object" attrs="{'invisible': [('state', 'in', ('in_queue', 'done'))]}" class="oe_highlight" string="Send Now"
|
||||
confirm="This will send the email to all recipients. Do you still want to proceed ?"/>
|
||||
<button name="cancel_mass_mailing" type="object" attrs="{'invisible': [('state', '!=', 'in_queue')]}" class="oe_highlight" string="Cancel"/>
|
||||
<button name="action_schedule_date" type="object" attrs="{'invisible': [('state', 'in', ('in_queue', 'done'))]}" class="btn-default" string="Schedule"/>
|
||||
<button name="action_test_mailing" type="object" class="btn-default" string="Test"/>
|
||||
<button name="cancel_mass_mailing" type="object" attrs="{'invisible': [('state', '!=', 'in_queue')]}" class="btn-default" string="Cancel"/>
|
||||
<button name="retry_failed_mail" type="object" attrs="{'invisible': ['|', ('state', '!=', 'done'), ('failed', '=', 0)]}" class="oe_highlight" string="Retry"/>
|
||||
|
||||
<field name="state" readonly="1" widget="statusbar"/>
|
||||
@@ -532,7 +533,7 @@
|
||||
<field name="attachment_ids" widget="many2many_binary" string="Attach a file" class="oe_inline"/>
|
||||
</div>
|
||||
<field name="mail_server_id" groups="base.group_no_one" options="{'no_create': True, 'no_open': True}"/>
|
||||
<field name="schedule_date" />
|
||||
<field name="schedule_date" groups='base.group_no_one'/>
|
||||
<field name="keep_archives" groups="base.group_no_one"/>
|
||||
<field name="create_date" readonly="1" attrs="{'invisible': [('create_date', '=', False)]}"/>
|
||||
<field name="sent_date" readonly="1" attrs="{'invisible': [('sent_date', '=', False)]}"/>
|
||||
|
||||
@@ -4,3 +4,4 @@
|
||||
from . import test_mailing
|
||||
from . import mail_compose_message
|
||||
from . import mass_mailing_list_merge
|
||||
from . import mass_mailing_schedule_date
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class MassMailingScheduleDate(models.TransientModel):
|
||||
_name = 'mass.mailing.schedule.date'
|
||||
_description = 'Schedule in the Future'
|
||||
|
||||
schedule_date = fields.Datetime(string='Schedule in the Future')
|
||||
mass_mailing_id = fields.Many2one('mail.mass_mailing', required=True)
|
||||
|
||||
@api.constrains('schedule_date')
|
||||
def _check_schedule_date(self):
|
||||
for scheduler in self:
|
||||
if scheduler.schedule_date < fields.Datetime.now():
|
||||
raise ValidationError(_('Please select a date equal/or greater than the current date.'))
|
||||
|
||||
def set_schedule_date(self):
|
||||
self.mass_mailing_id.write({'schedule_date': self.schedule_date, 'state': 'in_queue'})
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<record id="mass_mailing_schedule_date_view_form" model="ir.ui.view">
|
||||
<field name="name">mass.mailing.schedule.date.view.form</field>
|
||||
<field name="model">mass.mailing.schedule.date</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Take Future Schedule Date">
|
||||
<group>
|
||||
<group>
|
||||
<field name="schedule_date" required="1"/>
|
||||
</group>
|
||||
</group>
|
||||
<footer>
|
||||
<button string="Schedule" name="set_schedule_date" type="object" class="btn-primary"/>
|
||||
<button string="Discard " class="btn-default" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="mass_mailing_schedule_date_action" model="ir.actions.act_window">
|
||||
<field name="name">When do you want to send your mailing?</field>
|
||||
<field name="res_model">mass.mailing.schedule.date</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user