diff --git a/base_sms_client/__manifest__.py b/base_sms_client/__manifest__.py index 93e5d36..52c1138 100644 --- a/base_sms_client/__manifest__.py +++ b/base_sms_client/__manifest__.py @@ -33,7 +33,11 @@ "views/server_action_view.xml", "data/sms_gateway_data.xml", "wizard/mass_sms_view.xml", - "views/smstemplate_view.xml" + "views/smstemplate_view.xml", + "static/src/xml/templates.xml", + ], + 'qweb': [ + 'static/src/xml/inherit_chatter.xml', ], "installable": True, } diff --git a/base_sms_client/static/src/js/override_chatter.js b/base_sms_client/static/src/js/override_chatter.js new file mode 100644 index 0000000..40b2a4a --- /dev/null +++ b/base_sms_client/static/src/js/override_chatter.js @@ -0,0 +1,40 @@ +odoo.define('mail.Chatter.sms', function (require) { + "use strict"; + + var chatter = require('mail.Chatter'); + + chatter.include({ + + events: _.extend({}, chatter.prototype.events, { + 'click .o_chatter_button_send_sms': '_onSendSMS', + }), + + /** + * Performs the action to open the SMS window. + * + * @private + */ + _onSendSMS: function () { + var self = this + this._rpc({ + model: 'wizard.mass.sms', + method: 'redirect_to_sms_wizard', + args: [[]], + kwargs: { + 'id':this.record.res_id, + 'model':this.record.model, + }, + context: this.record.getContext(), + }).then(function (result) { + self.do_action(result, { + additional_context: { + 'active_ids': [self.record.res_id], + 'active_id': [self.record.res_id], + 'active_model': self.record.model, + }, + }) + }); + }, + + }); +}); diff --git a/base_sms_client/static/src/xml/inherit_chatter.xml b/base_sms_client/static/src/xml/inherit_chatter.xml new file mode 100644 index 0000000..df490c7 --- /dev/null +++ b/base_sms_client/static/src/xml/inherit_chatter.xml @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/base_sms_client/static/src/xml/templates.xml b/base_sms_client/static/src/xml/templates.xml new file mode 100644 index 0000000..285cd32 --- /dev/null +++ b/base_sms_client/static/src/xml/templates.xml @@ -0,0 +1,8 @@ + + + + diff --git a/base_sms_client/wizard/mass_sms.py b/base_sms_client/wizard/mass_sms.py index 1de99f3..b9bb80f 100644 --- a/base_sms_client/wizard/mass_sms.py +++ b/base_sms_client/wizard/mass_sms.py @@ -18,6 +18,11 @@ class WizardMassSms(models.TransientModel): def _default_get_partner(self): if self._context.get('active_model') == 'res.partner': return self._context.get('active_ids') + else: + rec = self.env[self._context.get('active_model')].browse( + self._context.get('active_id')) + if hasattr(rec, 'message_follower_ids'): + rec.message_follower_ids.mapped('partner_id') gateway_id = fields.Many2one( 'sms.gateway', @@ -76,7 +81,27 @@ class WizardMassSms(models.TransientModel): @api.multi def send(self): sms_obj = self.env['sms.sms'] - partner_obj = self.env['res.partner'] - for partner in partner_obj.browse(self._context.get('active_ids')): + for partner in self.partner_ids: vals = self._prepare_sms_vals(partner) sms_obj.create(vals) + src_model = self.env[self._context.get('active_model')] + if hasattr(src_model, 'message_follower_ids'): + rec = src_model.browse(self._context.get('active_id')) + rec.message_post(body=self.message) + self.env['bus.bus'].sendone( + 'refresh', [self.env.cr.dbname, self._name, self._uid]) + return {'type': 'ir.actions.act_window_close'} + + def redirect_to_sms_wizard(self, **kwargs): + id = kwargs.get("id") + model = kwargs.get("model") + action = self.env['wizard.mass.sms'].action_wizard_mass_sms() + action['src_model'] = model + action['domain'] = [('res_id', '=', id)] + return action + + @api.model + def action_wizard_mass_sms(self): + action = self.env.ref( + 'base_sms_client.action_wizard_mass_sms').read()[0] + return action diff --git a/clicksend_sms_client/models/sms_gateway.py b/clicksend_sms_client/models/sms_gateway.py index a0706aa..44d8d14 100644 --- a/clicksend_sms_client/models/sms_gateway.py +++ b/clicksend_sms_client/models/sms_gateway.py @@ -63,8 +63,7 @@ class SmsSms(models.Model): params.update({ 'password': '*****', 'to': '*****', - 'smsAccount': '*****', - 'login': '*****', + 'username': '*****', }) _logger.debug("Call ClickSend API : %s params %s", params['url'], params)