diff options
| author | Thibault Delavallée <tde@odoo.com> | 2019-06-20 09:55:30 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-07-12 14:54:11 +0000 |
| commit | 423cf93eb32df363c16ccabab2fddaea384ceac7 (patch) | |
| tree | a1920e9d1dae14b7661cf59c75fe04cf46b683d6 /addons/sms/models/mail_thread.py | |
| parent | 45555bdd1fddb988bfa54ff54f1bc1887d0dc1df (diff) | |
[IMP] sms: add UX elements to use SMS notifications
Purpose of this commit is to allow users to have a feedback on SMS
notifications status in chatter. This commit contains notably
* an update of systray widget that now handles SMS failures. Those are
displayed in another item of the systray and redirect to documents having
an SMS failure;
* an update of chatter widgets to support SMS notifications in messages.
Failed notifications appear in red and allow to use the SMS resend
wizard;
Mail message model gains a new has_sms_error computed and searchable field
allowing to filter on messages having failed SMS notifications. Mail thread
model gains a new message_has_sms_error computed and searchable field, based
on the one on mail.message. It allows to filter on records with failed SMS
messages directly from the systray. That way clicking on the systray entry
redirects to the right records.
Related to task 1922163
Linked to PR #33510
Co-Authored-By: Thibault Delavallee <tde@odoo.com>
Co-Authored-By: Pierre Rousseau <pro@odoo.com>
Diffstat (limited to 'addons/sms/models/mail_thread.py')
| -rw-r--r-- | addons/sms/models/mail_thread.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/addons/sms/models/mail_thread.py b/addons/sms/models/mail_thread.py index b088309cbfe..a432d29a2d3 100644 --- a/addons/sms/models/mail_thread.py +++ b/addons/sms/models/mail_thread.py @@ -3,7 +3,7 @@ import logging -from odoo import api, models +from odoo import api, models, fields from odoo.addons.phone_validation.tools import phone_validation from odoo.tools import html2plaintext @@ -13,6 +13,29 @@ _logger = logging.getLogger(__name__) class MailThread(models.AbstractModel): _inherit = 'mail.thread' + message_has_sms_error = fields.Boolean( + 'SMS Delivery error', compute='_compute_message_has_sms_error', search='_search_message_has_sms_error', + help="If checked, some messages have a delivery error.") + + @api.multi + def _compute_message_has_sms_error(self): + res = {} + if self.ids: + self._cr.execute(""" SELECT msg.res_id, COUNT(msg.res_id) FROM mail_message msg + RIGHT JOIN mail_message_res_partner_needaction_rel rel + ON rel.mail_message_id = msg.id AND rel.notification_type = 'sms' AND rel.notification_status in ('exception') + WHERE msg.author_id = %s AND msg.model = %s AND msg.res_id in %s AND msg.message_type != 'user_notification' + GROUP BY msg.res_id""", + (self.env.user.partner_id.id, self._name, tuple(self.ids),)) + res.update(self._cr.fetchall()) + + for record in self: + record.message_has_sms_error = bool(res.get(record._origin.id, 0)) + + @api.model + def _search_message_has_sms_error(self, operator, operand): + return ['&', ('message_ids.has_sms_error', operator, operand), ('message_ids.author_id', '=', self.env.user.partner_id.id)] + def _sms_get_default_partners(self): """ This method will likely need to be overriden by inherited models. :returns partners: recordset of res.partner |
