[IMP] mass_mailing(_sms): add a button to send mailing & sms from mailing list
This commit introduces a button "Send New Mailing" & "Send New SMS" on the mailing list so that one can direct send mailing & sms from a mailing list. The current list will be set as default one in the mailing. TaskId-2702607 Part-of: odoo/odoo#82107
This commit is contained in:
@@ -160,6 +160,8 @@ class MassMailingList(models.Model):
|
||||
'context': {
|
||||
**self.env.context,
|
||||
'default_contact_list_ids': self.ids,
|
||||
'default_mailing_type': 'mail',
|
||||
'default_model_id': self.env['ir.model']._get_id('mailing.list'),
|
||||
},
|
||||
'target': 'current',
|
||||
'view_type': 'form',
|
||||
|
||||
@@ -119,6 +119,19 @@ class TestMailingListMerge(MassMailCommon):
|
||||
self.assertEqual(contact.subscription_ids[0].opt_out_datetime, datetime(2022, 1, 1, 12, 0, 0))
|
||||
self.assertFalse(contact.subscription_ids[1].opt_out_datetime)
|
||||
|
||||
@users('user_marketing')
|
||||
def test_mailing_list_action_send_mailing(self):
|
||||
mailing_ctx = self.mailing_list_1.action_send_mailing().get('context', {})
|
||||
form = Form(self.env['mailing.mailing'].with_context(mailing_ctx))
|
||||
form.subject = 'Test Mail'
|
||||
mailing = form.save()
|
||||
# Check that mailing model and mailing list are set properly
|
||||
self.assertEqual(
|
||||
mailing.mailing_model_id, self.env['ir.model']._get('mailing.list'),
|
||||
'Should have correct mailing model set')
|
||||
self.assertEqual(mailing.contact_list_ids, self.mailing_list_1, 'Should have correct mailing list set')
|
||||
self.assertEqual(mailing.mailing_type, 'mail', 'Should have correct mailing_type')
|
||||
|
||||
@users('user_marketing')
|
||||
def test_mailing_list_contact_copy_in_context_of_mailing_list(self):
|
||||
MailingContact = self.env['mailing.contact']
|
||||
|
||||
@@ -39,6 +39,10 @@
|
||||
<field name="model">mailing.list</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Contact List">
|
||||
<header>
|
||||
<button name="action_send_mailing" string="Send Mailing"
|
||||
type="object" class="btn btn-primary"/>
|
||||
</header>
|
||||
<sheet>
|
||||
<div class="oe_button_box" name="button_box">
|
||||
<button name="action_view_contacts"
|
||||
|
||||
@@ -27,6 +27,22 @@ class MailingList(models.Model):
|
||||
action['context'] = dict(action.get('context', {}), search_default_filter_valid_sms_recipient=1)
|
||||
return action
|
||||
|
||||
def action_send_mailing_sms(self):
|
||||
view = self.env.ref('mass_mailing_sms.mailing_mailing_view_form_sms')
|
||||
action = self.env["ir.actions.actions"]._for_xml_id('mass_mailing_sms.mailing_mailing_action_sms')
|
||||
action.update({
|
||||
'context': {
|
||||
'default_contact_list_ids': self.ids,
|
||||
'default_model_id': self.env['ir.model']._get_id('mailing.list'),
|
||||
'default_mailing_type': 'sms',
|
||||
},
|
||||
'target': 'current',
|
||||
'view_type': 'form',
|
||||
'views': [(view.id, 'form')],
|
||||
})
|
||||
|
||||
return action
|
||||
|
||||
def _get_contact_statistics_fields(self):
|
||||
""" See super method docstring for more info.
|
||||
Adds:
|
||||
|
||||
@@ -6,3 +6,4 @@ from . import test_mailing_internals
|
||||
from . import test_mailing_retry
|
||||
from . import test_mailing_sms_ab_testing
|
||||
from . import test_mailing_ui
|
||||
from . import test_mailing_list
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.mass_mailing_sms.tests.common import MassSMSCommon
|
||||
from odoo.tests.common import Form, users
|
||||
|
||||
|
||||
class TestMailingListSms(MassSMSCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestMailingListSms, cls).setUpClass()
|
||||
cls._create_mailing_list()
|
||||
|
||||
@users('user_marketing')
|
||||
def test_mailing_list_action_send_sms(self):
|
||||
sms_ctx = self.mailing_list_1.action_send_mailing_sms().get('context', {})
|
||||
form = Form(self.env['mailing.mailing'].with_context(sms_ctx))
|
||||
form.sms_subject = 'Test SMS'
|
||||
form.body_plaintext = 'Test sms body'
|
||||
sms = form.save()
|
||||
# Check that mailing model and mailing list are set properly
|
||||
self.assertEqual(
|
||||
sms.mailing_model_id, self.env['ir.model']._get('mailing.list'),
|
||||
'Should have correct mailing model set')
|
||||
self.assertEqual(sms.contact_list_ids, self.mailing_list_1, 'Should have correct mailing list set')
|
||||
self.assertEqual(sms.mailing_type, 'sms', 'Should have correct mailing_type')
|
||||
@@ -29,6 +29,18 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="mailing_list_view_form" model="ir.ui.view">
|
||||
<field name="name">mailing.list.view.form.inherit.sms</field>
|
||||
<field name="model">mailing.list</field>
|
||||
<field name="inherit_id" ref="mass_mailing.mailing_list_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//button[@name='action_send_mailing']" position="after">
|
||||
<button name="action_send_mailing_sms" string="Send SMS"
|
||||
type="object" class="btn btn-primary"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="mailing_list_action_sms" model="ir.actions.act_window">
|
||||
<field name="name">Mailing Lists</field>
|
||||
<field name="res_model">mailing.list</field>
|
||||
|
||||
Reference in New Issue
Block a user