From cc3df43a809d4b8505951616861da1d1e1bc35a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Gil=20Sorribes?= Date: Mon, 8 Apr 2019 12:43:33 +0200 Subject: [PATCH] fixup and add auto-refresh chatter when sms sent --- base_sms_client/__manifest__.py | 1 + .../static/src/js/override_chatter.js | 28 +++++++++++++------ base_sms_client/wizard/mass_sms.py | 19 ++++++++----- clicksend_sms_client/__manifest__.py | 5 +--- clicksend_sms_client/models/sms_gateway.py | 8 +++--- oca_dependencies.txt | 3 +- 6 files changed, 39 insertions(+), 25 deletions(-) diff --git a/base_sms_client/__manifest__.py b/base_sms_client/__manifest__.py index 52c1138..f05f09d 100644 --- a/base_sms_client/__manifest__.py +++ b/base_sms_client/__manifest__.py @@ -12,6 +12,7 @@ "depends": ['mail', 'base_phone', 'keychain', + 'bus', ], 'author': 'Julius Network Solutions,SYLEAM,' 'Odoo Community Association (OCA),Akretion', diff --git a/base_sms_client/static/src/js/override_chatter.js b/base_sms_client/static/src/js/override_chatter.js index 40b2a4a..7912c93 100644 --- a/base_sms_client/static/src/js/override_chatter.js +++ b/base_sms_client/static/src/js/override_chatter.js @@ -2,6 +2,7 @@ odoo.define('mail.Chatter.sms', function (require) { "use strict"; var chatter = require('mail.Chatter'); + var bus = require('bus.bus').bus; chatter.include({ @@ -9,6 +10,16 @@ odoo.define('mail.Chatter.sms', function (require) { 'click .o_chatter_button_send_sms': '_onSendSMS', }), + start: function() { + this._super.apply(this, arguments); + var channel = 'wizard.mass.sms'; + bus.add_channel(channel); + bus.on('notification', this, function () { + var self = this; + self.trigger_up('reload'); + }); + }, + /** * Performs the action to open the SMS window. * @@ -26,15 +37,14 @@ odoo.define('mail.Chatter.sms', function (require) { }, 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, - }, - }) - }); + 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/wizard/mass_sms.py b/base_sms_client/wizard/mass_sms.py index b9bb80f..6f91caf 100644 --- a/base_sms_client/wizard/mass_sms.py +++ b/base_sms_client/wizard/mass_sms.py @@ -4,7 +4,7 @@ # Copyright (C) 2015 Valentin Chemiere # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import models, fields, api +from odoo import models, fields, api, _ class WizardMassSms(models.TransientModel): @@ -84,14 +84,19 @@ class WizardMassSms(models.TransientModel): 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]) + 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')) + self.post_message(rec) return {'type': 'ir.actions.act_window_close'} + def post_message(self, rec): + channel = 'wizard.mass.sms' + message = _("SMS Message (%s) sent to %s" % ( + self.message, ', '.join(self.partner_ids.mapped('name')))) + rec.message_post(body=message) + self.env['bus.bus'].sendone(channel, []) + def redirect_to_sms_wizard(self, **kwargs): id = kwargs.get("id") model = kwargs.get("model") diff --git a/clicksend_sms_client/__manifest__.py b/clicksend_sms_client/__manifest__.py index 7b6fd7e..259b22d 100644 --- a/clicksend_sms_client/__manifest__.py +++ b/clicksend_sms_client/__manifest__.py @@ -6,10 +6,7 @@ 'name': 'ClickSend SMS Client', 'version': '11.0.1.0.1', 'license': 'AGPL-3', - 'depends': ['mail', - 'base_sms_client', - 'keychain', - ], + 'depends': ['base_sms_client'], 'author': 'Eficent,' 'Odoo Community Association (OCA)', 'website': 'https://github.com/OCA/connector-telephony', diff --git a/clicksend_sms_client/models/sms_gateway.py b/clicksend_sms_client/models/sms_gateway.py index 44d8d14..b1d91c1 100644 --- a/clicksend_sms_client/models/sms_gateway.py +++ b/clicksend_sms_client/models/sms_gateway.py @@ -7,7 +7,7 @@ from odoo import api, models, fields from ..models.keychain import CLICKSEND_KEYCHAIN_NAMESPACE import requests import logging -from xml.etree.ElementTree import XML, fromstring, tostring +from xml.etree.ElementTree import fromstring _logger = logging.getLogger(__name__) @@ -23,9 +23,9 @@ class SmsClient(models.Model): for rec in self: keychain = rec.env['keychain.account'] # TODO: implement suspend_security module - #if rec._check_permissions(): + # if rec._check_permissions(): # retrieve = keychain.suspend_security().retrieve - #else: + # else: # retrieve = keychain.retrieve retrieve = keychain.retrieve accounts = retrieve( @@ -42,7 +42,7 @@ class SmsSms(models.Model): keychain_account = self.gateway_id._provider_get_provider_conf() params = { 'username': keychain_account['login'], - 'key': keychain_account.get_password(), + 'key': keychain_account._get_password(), 'senderid': self.gateway_id.from_provider, 'url': self.gateway_id.url, 'to': self._convert_to_e164(self.mobile), diff --git a/oca_dependencies.txt b/oca_dependencies.txt index a89069d..6a8d414 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1 +1,2 @@ -server-tools \ No newline at end of file +server-tools +server-auth \ No newline at end of file