[IMP] mass_mailing: add schedule button that opens a wizard for scheduling date

Purpose of this commit is to re-arrange mass mailing buttons and to add
a button for scheduling mass mailing in future :

 * add schedule date in debug mode;
 * re-arrange all button;
 * add schedule in future button and on click open wizard to schedule future
   date;
 * on 'send now' button remove the useless '|' in domain;
 * add a small wizard to select the send date;

This commit is related to task ID 46932
This commit is contained in:
dip-odoo
2018-05-25 16:23:48 +02:00
committed by Thibault Delavallée
parent 8db7869f4d
commit bbda48231c
6 changed files with 64 additions and 4 deletions
+1
View File
@@ -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,6 +637,13 @@ 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'})
@@ -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)]}"/>
+1
View File
@@ -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>