[IMP] sms: add options for sms server actions

After updating email server actions we can improve SMS server actions the
same way. We can now post on documents using SMS notification mechanism
in addition to pure mass SMS sending.

A new field is added to handle the way of sending SMS, like we do for
email actions.

Task-2613245 (Server actions mail update / cleaning)

Part-of: odoo/odoo#75906
This commit is contained in:
Thibault Delavallée
2022-08-12 23:37:03 +02:00
parent b3fc41cc44
commit db54f5eff1
4 changed files with 50 additions and 7 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
{
'name': 'SMS gateway',
'version': '2.3',
'version': '2.4',
'category': 'Hidden/Tools',
'summary': 'SMS Text Messaging',
'description': """
+17 -3
View File
@@ -20,7 +20,12 @@ class ServerActions(models.Model):
ondelete='set null', readonly=False, store=True,
domain="[('model_id', '=', model_id)]",
)
sms_mass_keep_log = fields.Boolean('Log as Note', default=True)
sms_method = fields.Selection(
selection=[('sms', 'SMS'), ('comment', 'Post as Message'), ('note', 'Post as Note')],
string='Send as (SMS)',
compute='_compute_sms_method',
readonly=False, store=True,
help='Choose method for SMS sending:\nSMS: mass SMS\nPost as Message: log on document\nPost as Note: mass SMS with archives')
@api.depends('model_id', 'state')
def _compute_sms_template_id(self):
@@ -31,6 +36,15 @@ class ServerActions(models.Model):
if to_reset:
to_reset.sms_template_id = False
@api.depends('state')
def _compute_sms_method(self):
to_reset = self.filtered(lambda act: act.state != 'sms')
if to_reset:
to_reset.sms_method = False
other = self - to_reset
if other:
other.sms_method = 'sms'
def _check_model_coherency(self):
super()._check_model_coherency()
for action in self:
@@ -49,9 +63,9 @@ class ServerActions(models.Model):
composer = self.env['sms.composer'].with_context(
default_res_model=records._name,
default_res_ids=records.ids,
default_composition_mode='mass',
default_composition_mode='comment' if self.sms_method == 'comment' else 'mass',
default_template_id=self.sms_template_id.id,
default_mass_keep_log=self.sms_mass_keep_log,
default_mass_keep_log=self.sms_method == 'note',
).create({})
composer.action_send_sms()
return False
+4 -2
View File
@@ -11,8 +11,10 @@
context="{'default_model': model_name}"
attrs="{'invisible': [('state', '!=', 'sms')],
'required': [('state', '=', 'sms')]}"/>
<field name="sms_mass_keep_log"
attrs="{'invisible': [('state', '!=', 'sms')]}"/>
<field name="sms_method"
string="Send as"
attrs="{'invisible': [('state', '!=', 'sms')],
'required': [('state', '=', 'sms')]}"/>
</xpath>
</field>
</record>
@@ -2,8 +2,11 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.test_mail_sms.tests.common import TestSMSCommon, TestSMSRecipients
from odoo.tests import tagged
from odoo.tools import mute_logger
@tagged('ir_actions')
class TestServerAction(TestSMSCommon, TestSMSRecipients):
@classmethod
@@ -24,6 +27,7 @@ class TestServerAction(TestSMSCommon, TestSMSRecipients):
'name': 'Test SMS Action',
'model_id': cls.env['ir.model']._get('mail.test.sms').id,
'state': 'sms',
'sms_method': 'sms',
'sms_template_id': cls.sms_template.id,
'groups_id': cls.env.ref('base.group_user'),
})
@@ -51,7 +55,7 @@ class TestServerAction(TestSMSCommon, TestSMSRecipients):
self.assertSMSOutgoing(self.test_record.customer_id, None, content='Dear %s this is an SMS.' % self.test_record.display_name)
def test_action_sms_w_log(self):
self.action.sms_mass_keep_log = True
self.action.sms_method = 'note'
context = {
'active_model': 'mail.test.sms',
'active_ids': (self.test_record | self.test_record_2).ids,
@@ -65,3 +69,26 @@ class TestServerAction(TestSMSCommon, TestSMSRecipients):
self.assertSMSOutgoing(self.env['res.partner'], self.test_numbers_san[0], content='Dear %s this is an SMS.' % self.test_record_2.display_name)
self.assertSMSLogged(self.test_record_2, 'Dear %s this is an SMS.' % self.test_record_2.display_name)
@mute_logger('odoo.addons.sms.models.sms_sms')
def test_action_sms_w_post(self):
self.action.sms_method = 'comment'
context = {
'active_model': 'mail.test.sms',
'active_ids': (self.test_record | self.test_record_2).ids,
}
with self.with_user('employee'), self.mockSMSGateway():
self.action.with_user(self.env.user).with_context(**context).run()
self.assertSMSNotification(
[{'partner': self.test_record.customer_id}],
'Dear %s this is an SMS.' % self.test_record.display_name,
messages=self.test_record.message_ids[-1]
)
self.assertSMSNotification(
[{'partner': self.env['res.partner'],
'number': self.test_numbers_san[0]}],
'Dear %s this is an SMS.' % self.test_record_2.display_name,
messages=self.test_record_2.message_ids[-1]
)