Skip to content
Browse files

imp after review

  • Loading branch information...
pro-odoo committed Apr 18, 2019
1 parent bea169e commit cbfc5b7bd6f1834d442d037c5209128e049f02d5
@@ -3,9 +3,10 @@
import logging

from odoo import api, fields, models, _
from odoo import api, fields, models, tools, _
from odoo.exceptions import UserError
from odoo.addons.iap.models import iap
from odoo.addons.mail.wizard.mail_compose_message import _reopen

_logger = logging.getLogger(__name__)

@@ -30,7 +31,8 @@ class SendSMS(models.TransientModel):
use_active_domain = fields.Boolean()

recipient_ids = fields.One2many('sms.recipient', 'sms_composer_id', string='Recipients')
template_id = fields.Many2one('sms.template')
model = fields.Char()
template_id = fields.Many2one('sms.template', string='Use Template', domain="[('model', '=', model)]")
content = fields.Text(required=True)

@@ -53,10 +55,17 @@ def _get_records(self, model):
records = model.browse(self.env.context.get('active_id', []))
return records

def _get_number(self, record):
field_name = self.env.context.get('field_name')
if field_name in ['mobile', 'phone']:
return record[field_name]
return if else

def default_get(self, fields):
result = super(SendSMS, self).default_get(fields)
active_model = self.env.context.get('active_model')
result['model'] = active_model
model = self.env[active_model]
records = self._get_records(model)
if self.env.context.get('default_composition_mode') != 'mass_sms' \
@@ -70,8 +79,12 @@ def default_get(self, fields):
raise UserError(_('Missing mobile number for %s.') % ', '.join(missing_numbers))
result['recipient_ids'] = [(0, False, {
'number': if else
'number': self._get_number(recipient)
}) for recipient in recipients]
if not self.env.context.get('default_template_id'):
templates_id = self.env['sms.template'].search([('model', '=', active_model)])
if templates_id:
result['template_id'] = templates_id[0].id
return result

def action_send_sms(self):
@@ -106,5 +119,25 @@ def action_send_sms(self):
all_sms |= sms_ids
if hasattr(record, 'message_post_send_sms'):
record.message_post_send_sms(body, sms_ids)
record.message_post_send_sms(body.replace('\n', '<br/>'), sms_ids)

def save_as_template(self):
""" hit save as template button: current form value will be a new
template attached to the current document. """
for record in self:
model = self.env['ir.model']._get(record.model or 'mail.message')
model_name = or ''
record_name = record.recipient_ids and record.recipient_ids[0].partner_id and record.recipient_ids[0].partner_id.display_name or 'New Template'
template_name = "%s: %s" % (model_name, record_name)
values = {
'name': template_name,
'body': record.content or False,
'model_id': or False,
template = self.env['sms.template'].create(values)
# generate the saved template
return _reopen(self,, record.model, context=self._context)
@@ -21,9 +21,10 @@
<field name="composition_mode" invisible="1"/>
<field name="use_active_domain" invisible="1"/>
<field name="model" invisible="1"/>

<!-- Various warnings -->
<div colspan="2" class="oe_form_box_info bg-info oe_text_center"
<div colspan="2" class="oe_form_box_info bg-info oe_text_center mb-3"
attrs="{'invisible': [('composition_mode', '=', 'comment')]}">
<p attrs="{'invisible': [('use_active_domain', '=', False)]}">
@@ -47,7 +48,6 @@
<field class="oe_inline" name="use_active_domain"/>

<label for="recipient_ids" string="Recipients"/>
<span attrs="{'invisible': [('composition_mode', '!=', 'mass_sms')]}">
@@ -60,23 +60,23 @@

<field name="content" widget="sms_widget"/>
<group col="4">
<field name="template_id" options="{'no_create': True}"/>
<field name="template_id" options="{'no_create': True}"/>
<button string="Send SMS" type="object" class="oe_highlight" name="action_send_sms"/>
<button string="Close" class="oe_link" special="cancel" />
<button string="Send SMS" type="object" class="oe_highlight" name="action_send_sms"/>
<button string="Close" class="oe_link" special="cancel" />
<button icon="fa-lg fa-save" type="object" name="save_as_template" string="Save as new template"
class="float-right btn-secondary" help="Save as a new template"/>
<record id="send_sms_form_action" model="ir.actions.act_window">
<field name="name">Send SMS</field>
<field name="name">Send SMS Text Message</field>
<field name="res_model">sms.compose.message</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
@@ -67,6 +67,14 @@ def resend_sms_action(self):
return {'type': 'ir.actions.act_window_close'}

def ignore_sms_action(self):
for sms in self.sms_resend_ids:
sms.sms_id.state = 'canceled'
return {'type': 'ir.actions.act_window_close'}

def cancel_sms_action(self):
@@ -81,4 +89,4 @@ def buy_credits(self):
return {
'type': 'ir.actions.act_url',
'url': url,
@@ -34,7 +34,7 @@

<record id="sms_resend_action" model="ir.actions.act_window">
<field name="name">Resend sms</field>
<field name="name">Resend SMS Text Message</field>
<field name="res_model">sms.resend</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>

0 comments on commit cbfc5b7

Please sign in to comment.
You can’t perform that action at this time.