diff --git a/addons/sms/__manifest__.py b/addons/sms/__manifest__.py index d9c6583d91a..ae0dda96dd7 100644 --- a/addons/sms/__manifest__.py +++ b/addons/sms/__manifest__.py @@ -3,7 +3,7 @@ { 'name': 'SMS gateway', - 'version': '2.3', + 'version': '2.4', 'category': 'Hidden/Tools', 'summary': 'SMS Text Messaging', 'description': """ diff --git a/addons/sms/models/ir_actions_server.py b/addons/sms/models/ir_actions_server.py index f701b091c97..3c9f59453f3 100644 --- a/addons/sms/models/ir_actions_server.py +++ b/addons/sms/models/ir_actions_server.py @@ -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 diff --git a/addons/sms/views/ir_actions_server_views.xml b/addons/sms/views/ir_actions_server_views.xml index bbbf2573151..9b7b3726b2b 100644 --- a/addons/sms/views/ir_actions_server_views.xml +++ b/addons/sms/views/ir_actions_server_views.xml @@ -11,8 +11,10 @@ context="{'default_model': model_name}" attrs="{'invisible': [('state', '!=', 'sms')], 'required': [('state', '=', 'sms')]}"/> - + diff --git a/addons/test_mail_sms/tests/test_sms_server_actions.py b/addons/test_mail_sms/tests/test_sms_server_actions.py index 235012aa56d..dfe9d6ba163 100644 --- a/addons/test_mail_sms/tests/test_sms_server_actions.py +++ b/addons/test_mail_sms/tests/test_sms_server_actions.py @@ -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] + )