[FIX] sms: send SMS on transfer without traceback

Steps to reproduce:
- Create a SMS template with the 'Applies to' property set to
  Transfer (without this the action will never appear)
- Go to Transfer, pick one, open action and try to send a SMS

Issue:
Traceback

Cause:
When sending the SMS we try to modify the 'mobile' attribute of
'stock.picking' but it doesn't exist.

opw-3286153

X-original-commit: c84f952824bea4c1e0d5dcc7450d5e48a5637db8
Part-of: odoo/odoo#123716
This commit is contained in:
Eteil Djoumatchoua(etdj)
2023-06-12 10:02:22 +02:00
parent dc37979e7b
commit 16bb22f5fc
2 changed files with 20 additions and 1 deletions
+1 -1
View File
@@ -210,7 +210,7 @@ class SendSMS(models.TransientModel):
# on the numbers in the database.
records = records if records is not None else self._get_records()
records.ensure_one()
if not self.number_field_name:
if not self.number_field_name or self.number_field_name not in records:
self.numbers = self.recipient_single_number_itf or self.recipient_single_number
elif self.recipient_single_number_itf and self.recipient_single_number_itf != self.recipient_single_number:
records.write({self.number_field_name: self.recipient_single_number_itf})
@@ -121,6 +121,25 @@ class TestSMSComposerComment(SMSCommon, TestSMSRecipients):
self.assertSMSNotification([{'partner': self.test_record.customer_id, 'number': self.test_record.mobile_nbr}], 'Dear %s this is an SMS.' % self.test_record.display_name, messages)
def test_composer_comment_invalid_field(self):
""" Test the Send Message in SMS Composer when a Model does not contain a number field name """
test_record = self.env['mail.test.sms.partner'].create({
'name': 'Test',
'customer_id': self.partner_1.id,
})
sms_composer = self.env['sms.composer'].create({
'body': self._test_body,
'number_field_name': 'phone_nbr',
'recipient_single_number_itf': self.random_numbers_san[0],
'res_id': test_record.id,
'res_model': 'mail.test.sms.partner'
})
self.assertNotIn(','.join(test_record._fields), 'phone_nbr')
with self.mockSMSGateway():
sms_composer._action_send_sms()
self.assertSMSNotification([{'number': self.random_numbers_san[0]}], self._test_body)
def test_composer_comment_nofield(self):
""" Test the Send Message in SMS Composer when a Model does not contain any phone number related field """
test_record = self.env['mail.test.sms.partner'].create({'name': 'Test'})