[IMP] sms: allow users to resend SMS
Right now, for failed SMS, user have to go through each record one by one to resend the SMS, which is not ideal and user should be able to resend SMS in batch from the list view. This commit improves the behavior with following changes: * Introduces an action 'Resend' which is availabe on list view of the SMS. It enables resending multiple SMS (that are in error state). It also displays appropriate toast notifcation to users so they know how it worked (if few/none SMS sent successfully or there was no SMS that could be resent etc). * On the SMS form view, a new 'Retry' button is introduced, visible on SMS whrich are cancelled or in error state. It pushes the SMS back in sendng queue (outgoing state). * 'Cancel' button on form view now also appears in error state. * Uses the state-decorations on the list view for better identifications of the records (info for outgoing, muted for canceled and danger for error state). taskID-2465233 closes https://github.com/odoo/odoo/pull/67502
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from odoo import api, fields, models, tools
|
||||
from odoo import api, fields, models, tools, _
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -58,6 +58,35 @@ class SmsSms(models.Model):
|
||||
if auto_commit is True and not getattr(threading.currentThread(), 'testing', False):
|
||||
self._cr.commit()
|
||||
|
||||
def set_outgoing(self):
|
||||
self.state = 'outgoing'
|
||||
|
||||
def resend_failed(self):
|
||||
sms_to_send = self.filtered(lambda sms: sms.state == 'error')
|
||||
notification_title = _('Warning')
|
||||
notification_type = 'danger'
|
||||
notification_message = ''
|
||||
if sms_to_send:
|
||||
sms_to_send.send()
|
||||
success_sms = len(sms_to_send) - len(sms_to_send.exists())
|
||||
if success_sms > 0:
|
||||
notification_title = _('Success')
|
||||
notification_type = 'success'
|
||||
notification_message = _('%s out of the %s selected SMS Text Messages have successfully been resent.', success_sms, len(self))
|
||||
else:
|
||||
notification_message = _('The SMS Text Messages could not be resent.')
|
||||
else:
|
||||
notification_message = _('There are no SMS Text Messages to resend.')
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'display_notification',
|
||||
'params': {
|
||||
'title': notification_title,
|
||||
'message': notification_message,
|
||||
'type': notification_type,
|
||||
}
|
||||
}
|
||||
|
||||
def cancel(self):
|
||||
self.state = 'canceled'
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
<form string="SMS">
|
||||
<header>
|
||||
<button name="send" string="Send Now" type="object" states='outgoing' class="oe_highlight"/>
|
||||
<button name="cancel" string="Cancel" type="object" states='outgoing'/>
|
||||
<button name="set_outgoing" string="Retry" type="object" states='error,canceled'/>
|
||||
<button name="cancel" string="Cancel" type="object" states='error,outgoing'/>
|
||||
<field name="state" widget="statusbar"/>
|
||||
</header>
|
||||
<sheet>
|
||||
@@ -33,7 +34,7 @@
|
||||
<field name="name">sms.sms.view.tree</field>
|
||||
<field name="model">sms.sms</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="SMS Templates">
|
||||
<tree string="SMS Templates" decoration-muted="state == 'canceled'" decoration-info="state == 'outgoing'" decoration-danger="state == 'error'">
|
||||
<field name="number"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="state"/>
|
||||
@@ -64,5 +65,13 @@
|
||||
action="sms_sms_action"
|
||||
sequence="1"/>
|
||||
|
||||
<record id="ir_actions_server_sms_sms_resend" model="ir.actions.server">
|
||||
<field name="name">Resend</field>
|
||||
<field name="model_id" ref="sms.model_sms_sms"/>
|
||||
<field name="binding_model_id" ref="sms.model_sms_sms"/>
|
||||
<field name="binding_view_types">list</field>
|
||||
<field name="state">code</field>
|
||||
<field name="code">action = records.resend_failed()</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user