Skip to content
Permalink
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)

@api.onchange('template_id')
@@ -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 record.mobile if record.mobile else record.phone

@api.model
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, {
'partner_id': recipient.id,
'number': recipient.mobile if recipient.mobile else recipient.phone
'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):
sms_ids._send()
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)
all_sms._notify_sms_update()

@api.multi
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 = 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': model.id or False,
}
template = self.env['sms.template'].create(values)
# generate the saved template
record.write({'template_id': template.id})
record._onchange_template_id()
return _reopen(self, record.id, record.model, context=self._context)
@@ -21,9 +21,10 @@
<group>
<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)]}">
<strong>
@@ -47,7 +48,6 @@
<field class="oe_inline" name="use_active_domain"/>
</p>
</div>

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

<field name="content" widget="sms_widget"/>
</group>
<group col="4">
<field name="template_id" options="{'no_create': True}"/>
<group>
<group>
<field name="template_id" options="{'no_create': True}"/>
</group>
</group>
</sheet>
<footer>
<group>
<span>
<button string="Send SMS" type="object" class="oe_highlight" name="action_send_sms"/>
<button string="Close" class="oe_link" special="cancel" />
</span>
</group>
<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"/>
</footer>
</form>
</field>
</record>
<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):
self.sms_resend_ids.mapped('sms_id')._notify_sms_update()
return {'type': 'ir.actions.act_window_close'}

@api.multi
def ignore_sms_action(self):
self.ensure_one()
for sms in self.sms_resend_ids:
sms.sms_id.state = 'canceled'
self.sms_resend_ids.mapped('sms_id')._notify_sms_update()
return {'type': 'ir.actions.act_window_close'}

@api.multi
def cancel_sms_action(self):
self.ensure_one()
@@ -81,4 +89,4 @@ def buy_credits(self):
return {
'type': 'ir.actions.act_url',
'url': url,
}
}
@@ -34,7 +34,7 @@
</record>

<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.