[FW][FIX] sms: correctly render body in mass sms

When sending SMS on several records in comment mode (aka: post sms message
in batch) the body is sent as it is. This does not happen frequently as
default usage is either

  * comment on a single record -> body is rendered by onchange / compute;
  * mass SMS on several records -> body is rendered for all records then
    sent to all recipients;

Using comment mode in mass is not common, and is mainly achieved through
handcrafted actions. However this can be fixed by correctly rendering the
body before posting on all records.

Use addition of records instead of OR to keep ordering of created
messages when using SMS composer.

Spotted during Task-2613245 (Server actions mail update / cleaning)

closes odoo/odoo#97787

closes odoo/odoo#97890

closes odoo/odoo#97931

X-original-commit: odoo/odoo@1778a2c1b2
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Thibault Delavallée
2022-08-11 17:56:59 +02:00
parent ab97d81620
commit 6ca272aa05
2 changed files with 11 additions and 8 deletions
+5 -2
View File
@@ -219,9 +219,12 @@ class SendSMS(models.TransientModel):
subtype_id = self.env['ir.model.data']._xmlid_to_res_id('mail.mt_note')
messages = self.env['mail.message']
all_bodies = self._prepare_body_values(records)
for record in records:
messages |= record._message_sms(
self.body, subtype_id=subtype_id,
messages += record._message_sms(
all_bodies[record.id],
subtype_id=subtype_id,
number_field=self.number_field_name,
sms_numbers=self.sanitized_numbers.split(',') if self.sanitized_numbers else None)
return messages
@@ -228,11 +228,11 @@ class TestSMSComposerBatch(TestSMSCommon):
with self.mockSMSGateway():
messages = composer._action_send_sms()
for record in self.records:
for record, message in zip(self.records, messages):
self.assertSMSNotification(
[{'partner': record.customer_id}],
'Hello ${object.name} zizisse an SMS.',
messages
'Hello %s zizisse an SMS.' % record.name,
message
)
def test_composer_batch_res_ids(self):
@@ -248,11 +248,11 @@ class TestSMSComposerBatch(TestSMSCommon):
with self.mockSMSGateway():
messages = composer._action_send_sms()
for record in self.records:
for record, message in zip(self.records, messages):
self.assertSMSNotification(
[{'partner': record.customer_id}],
'Hello ${object.name} zizisse an SMS.',
messages
'Hello %s zizisse an SMS.' % record.name,
message
)