mirror of https://github.com/OCA/web.git
[MIG] web_notify: Migration to 11.0
- Use the 'session' class of the JS Framework (session no lounger bound to web client) - Test change: compare emitted & received messages based on content, not order. Using string comparison raises false positives.pull/911/merge
parent
92054cf8a7
commit
c1765f97c3
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
@ -6,7 +5,7 @@
|
|||
'name': 'Web Notify',
|
||||
'summary': """
|
||||
Send notification messages to user""",
|
||||
'version': '10.0.1.0.0',
|
||||
'version': '11.0.1.0.0',
|
||||
'description': 'Web Notify',
|
||||
'license': 'AGPL-3',
|
||||
'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
|
|
@ -3,24 +3,18 @@ odoo.define('web_notify.WebClient', function (require) {
|
|||
|
||||
var WebClient = require('web.WebClient');
|
||||
var base_bus = require('bus.bus');
|
||||
var session = require('web.session');
|
||||
|
||||
|
||||
WebClient.include({
|
||||
init: function(parent, client_options){
|
||||
this._super(parent, client_options);
|
||||
},
|
||||
show_application: function() {
|
||||
var res = this._super();
|
||||
this.start_polling();
|
||||
return res
|
||||
},
|
||||
on_logout: function() {
|
||||
var self = this;
|
||||
base_bus.bus.off('notification', this, this.bus_notification);
|
||||
this._super();
|
||||
},
|
||||
start_polling: function() {
|
||||
this.channel_warning = 'notify_warning_' + this.session.uid;
|
||||
this.channel_info = 'notify_info_' + this.session.uid;
|
||||
this.channel_warning = 'notify_warning_' + session.uid;
|
||||
this.channel_info = 'notify_info_' + session.uid;
|
||||
base_bus.bus.add_channel(this.channel_warning);
|
||||
base_bus.bus.add_channel(this.channel_info);
|
||||
base_bus.bus.on('notification', this, this.bus_notification);
|
||||
|
@ -33,7 +27,7 @@ WebClient.include({
|
|||
var message = notification[1];
|
||||
if (channel === self.channel_warning) {
|
||||
self.on_message_warning(message);
|
||||
} else if (channel == self.channel_info) {
|
||||
} else if (channel === self.channel_info) {
|
||||
self.on_message_info(message);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo.tests import common
|
||||
from odoo.addons.bus.models.bus import json_dump
|
||||
import json
|
||||
import mock
|
||||
|
||||
|
||||
|
@ -16,13 +16,11 @@ class TestResUsers(common.TransactionCase):
|
|||
json_dump(self.env.user.notify_info_channel_name))
|
||||
]
|
||||
existing = bus_bus.search(domain)
|
||||
self.env.user.notify_info(
|
||||
message='message', title='title', sticky=True)
|
||||
test_msg = {'message': 'message', 'title': 'title', 'sticky': True}
|
||||
self.env.user.notify_info(**test_msg)
|
||||
news = bus_bus.search(domain) - existing
|
||||
self.assertEqual(1, len(news))
|
||||
self.assertEqual(
|
||||
'{"message":"message","sticky":true,"title":"title"}',
|
||||
news.message)
|
||||
self.assertEqual(test_msg, json.loads(news.message))
|
||||
|
||||
def test_notify_warning(self):
|
||||
bus_bus = self.env['bus.bus']
|
||||
|
@ -31,13 +29,11 @@ class TestResUsers(common.TransactionCase):
|
|||
json_dump(self.env.user.notify_warning_channel_name))
|
||||
]
|
||||
existing = bus_bus.search(domain)
|
||||
self.env.user.notify_warning(
|
||||
message='message', title='title', sticky=True)
|
||||
test_msg = {'message': 'message', 'title': 'title', 'sticky': True}
|
||||
self.env.user.notify_warning(**test_msg)
|
||||
news = bus_bus.search(domain) - existing
|
||||
self.assertEqual(1, len(news))
|
||||
self.assertEqual(
|
||||
'{"message":"message","sticky":true,"title":"title"}',
|
||||
news.message)
|
||||
self.assertEqual(test_msg, json.loads(news.message))
|
||||
|
||||
def test_notify_many(self):
|
||||
# check that the notification of a list of users is done with
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<template id="assets_backend" name="web_noify assets" inherit_id="web.assets_backend">
|
||||
<template id="assets_backend" name="web_notify assets" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/web_notify/static/src/js/web_client.js"/>
|
||||
</xpath>
|
||||
|
|
Loading…
Reference in New Issue