diff options
| author | Thibault Delavallée <tde@odoo.com> | 2020-04-30 13:27:26 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-04-30 14:47:49 +0000 |
| commit | c5c7a02302f6095c2ecf1e215421a8c9ff630638 (patch) | |
| tree | d106f752ab55b393b625f35f7b1b8325b16244fd /addons/sms | |
| parent | 9a3581d925af1a00849418608fd5db6d3cae203b (diff) | |
[FIX][IMP] sms: create failed notification when SMS-ing record without any phone number
When no valid phone number was found on a record, and when using _message_sms
directly, no SMS and no notification was created. You could therefore think
everything was ok while it was actually not.
Instead we now create failed notifications. It allows to be notified of it
and fix numbers through cancel / resend wizards.
Task ID 2244192
closes odoo/odoo#50486
X-original-commit: baecdfaa2d31714a20d1fb8af7799af1805cd939
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/sms')
| -rw-r--r-- | addons/sms/models/mail_thread.py | 22 | ||||
| -rw-r--r-- | addons/sms/tests/common.py | 3 |
2 files changed, 19 insertions, 6 deletions
diff --git a/addons/sms/models/mail_thread.py b/addons/sms/models/mail_thread.py index e39eb5c029d..1db4ecd9d53 100644 --- a/addons/sms/models/mail_thread.py +++ b/addons/sms/models/mail_thread.py @@ -215,8 +215,12 @@ class MailThread(models.AbstractModel): sms_pid_to_number[info_partner_ids[0]] = info_number if info_partner_ids: partner_ids = info_partner_ids + (partner_ids or []) - if info_number and not info_partner_ids: - sms_numbers = [info_number] + (sms_numbers or []) + if not info_partner_ids: + if info_number: + sms_numbers = [info_number] + (sms_numbers or []) + # will send a falsy notification allowing to fix it through SMS wizards + elif not sms_numbers: + sms_numbers = [False] if subtype_id is False: subtype_id = self.env['ir.model.data'].xmlid_to_res_id('mail.mt_note') @@ -284,9 +288,14 @@ class MailThread(models.AbstractModel): tocreate_numbers = [ value['sanitized'] or original for original, value in sanitized.items() - if value['code'] != 'empty' ] - sms_create_vals += [dict(sms_base_vals, partner_id=False, number=n) for n in tocreate_numbers] + sms_create_vals += [dict( + sms_base_vals, + partner_id=False, + number=n, + state='outgoing' if n else 'error', + error_code='' if n else 'sms_number_missing', + ) for n in tocreate_numbers] # create sms and notification existing_pids, existing_numbers = [], [] @@ -313,7 +322,8 @@ class MailThread(models.AbstractModel): 'notification_type': 'sms', 'sms_id': sms.id, 'is_read': True, # discard Inbox notification - 'notification_status': 'ready', + 'notification_status': 'ready' if sms.state == 'outgoing' else 'exception', + 'failure_type': '' if sms.state == 'outgoing' else sms.error_code, } for sms in sms_all if (sms.partner_id and sms.partner_id.id not in existing_pids) or (not sms.partner_id and sms.number not in existing_numbers)] if notif_create_values: self.env['mail.notification'].sudo().create(notif_create_values) @@ -332,6 +342,6 @@ class MailThread(models.AbstractModel): }) if sms_all and not put_in_queue: - sms_all.send(auto_commit=False, raise_exception=False) + sms_all.filtered(lambda sms: sms.state == 'outgoing').send(auto_commit=False, raise_exception=False) return True diff --git a/addons/sms/tests/common.py b/addons/sms/tests/common.py index a5f4e511cfd..10335fc1890 100644 --- a/addons/sms/tests/common.py +++ b/addons/sms/tests/common.py @@ -130,6 +130,9 @@ class MockSMS(common.BaseCase): """ partners = self.env['res.partner'].concat(*list(p['partner'] for p in recipients_info if p.get('partner'))) numbers = [p['number'] for p in recipients_info if p.get('number')] + # special case of void notifications: check for False / False notifications + if not partners and not numbers: + numbers = [False] base_domain = [ '|', ('res_partner_id', 'in', partners.ids), '&', ('res_partner_id', '=', False), ('sms_number', 'in', numbers), |
