Browse Source

Merge 1bc38852f7 into ad79aa45cf

pull/972/merge
gabrielcardoso21 5 years ago
committed by GitHub
parent
commit
7b0caa7f71
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 78
      web_auto_refresh/README.rst
  2. 5
      web_auto_refresh/__init__.py
  3. 18
      web_auto_refresh/__manifest__.py
  4. 81
      web_auto_refresh/static/src/js/web_auto_refresh.js
  5. 13
      web_auto_refresh/views/web_auto_refresh.xml

78
web_auto_refresh/README.rst

@ -0,0 +1,78 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3
Web Auto Refresh
===========
Standard odoo 10.0 only support auto refreshing the inbox message, for kanban and list view when underlying model data updated by others, even though the auto search option in ir.actions.act_window activated, system will not auto refresh the kanban and list view as expected, this small module just fills this gap, this module is useful for keep monitoring orders, tickets etc without manual refresh the browser.
Installation
============
To install this module, you need to:
Configuration
=============
To configure this module, you need to:
1. go to setting->technical->actions->window actions, find the desired action, activate the auto search Check box
2. add one automated action for the target model , in the linked server action add the following python code, this automated action can be applied(when to run) to creation, update or delete per your requirement
model.env['bus.bus'].sendone('web_auto_refresh', model._name)
Usage
=====
To use this module, you need to:
1. goes to the list or kanban view of the selected model, in display mode
2. in another session(login via another browser and other computer), create, change or delete records of the model, then save
3. the original list or kanban view in display mode will be auto refreshed
For further information, please visit:
* https://www.odoo.com/forum/help-1
Known issues / Roadmap
======================
* From Techical point of view, the high level implementation detail is as following
1. on backend(Python code triggered by automated server action), generate one record into model bus.bus(notification) when relevant model data updated(create/write/unlink) by calling the bus.sendone('channel','message')
2. on frontend(javascript), declare the event listener to handle the notification message, check to see whether the notification(message) is relevant for the current view/ user, if so auto refresh the view, either call reload(),do_reload(), or do_search_view_search()
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/{project_repo}/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/{project_repo}/issues/new?body=module:%20{module_name}%0Aversion:%20{version}%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Gabriel Cardoso de Faria <gabriel.cardoso@kmee.com.br>
* Fisher Yu <szufisher@gmail.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.

5
web_auto_refresh/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Kmee Informática
# Gabriel Cardoso de Faria <gabriel.cardoso@kmee.com.br>
# Fisher Yu <szufisher@gmail.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

18
web_auto_refresh/__manifest__.py

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Kmee Informática
# Gabriel Cardoso de Faria <gabriel.cardoso@kmee.com.br>
# Fisher Yu <szufisher@gmail.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{
'name': 'Web Auto Refresh',
'version': '10.0.1.0.0',
'author': 'Gabriel Cardoso de Faria, Fisher Yu, Odoo Community Association (OCA)',
'category': 'Base',
'website': 'https://github.com/kmee',
'depends': ['web', 'bus', 'mail'],
'data': [
'views/web_auto_refresh.xml',
],
'installable': True
}

81
web_auto_refresh/static/src/js/web_auto_refresh.js

@ -0,0 +1,81 @@
/* Copyright 2018 Kmee Informática
* Gabriel Cardoso de Faria <gabriel.cardoso@kmee.com.br>
* Fisher Yu <szufisher@gmail.com>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
odoo.define('web_auto_refresh', function (require) {
"use strict";
let WebClient = require('web.WebClient');
let bus = require('bus.bus');
let session = require('web.session');
WebClient.include({
init: function(parent, client_options){
this._super(parent, client_options);
this.known_bus_channels = [];
this.known_bus_events = [];
},
show_application: function() {
let res = this._super();
this.start_polling();
return res;
},
on_logout: function() {
bus.off('notification', this, this.bus_notification);
_(this.known_bus_channels).each(function (channel) {
bus.bus.delete_channel(channel);
});
_(this.known_bus_events).each(function(e) {
this.bus_off(e[0], e[1]);
});
this._super();
},
start_polling: function() {
this.declare_bus_channel();
bus.bus.on('notification', this, this.bus_notification);
bus.bus.start_polling();
},
bus_notification: function(notification) {
let channel = notification[0][0];
if (this.known_bus_channels.indexOf(channel) !== -1) {
let message = notification[0][1];
bus.bus.trigger(channel, message);
}
},
bus_on: function(eventname, eventfunction) {
console.log(eventname, eventfunction);
bus.bus.on(eventname, this, eventfunction);
this.known_bus_events.push([eventname, eventfunction]);
},
bus_off: function(eventname, eventfunction) {
bus.bus.off(eventname, this, eventfunction);
let index = _.indexOf(this.known_bus_events, [eventname, eventfunction]);
this.known_bus_events.splice(index, 1);
},
declare_bus_channel: function() {
let channel = 'web_auto_refresh';
this.bus_on(channel, function(message) { // generic auto referesh
let inner_widget = this.action_manager.inner_widget;
if (inner_widget && inner_widget.active_view){
let controller = this.action_manager.inner_widget.active_view.controller;
let action = this.action_manager.inner_widget.action;
if ( action.auto_search && controller.model === message ){
if (inner_widget.active_view.type === "kanban")
controller.do_reload(); // kanban view has reload function, but only do_reload works as expected
if (inner_widget.active_view.type === "list" &&
! controller.$buttons.hasClass('oe_editing') &&
! controller.grouped)
controller.reload(); // list view only has reload
}
}
});
this.add_bus_channel(channel);
},
add_bus_channel: function(channel) {
if (this.known_bus_channels.indexOf(channel) === -1) {
bus.bus.add_channel(channel);
this.known_bus_channels.push(channel);
}
},
})
});

13
web_auto_refresh/views/web_auto_refresh.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 Kmee Informática
Gabriel Cardoso de Faria <gabriel.cardoso@kmee.com.br>
Fisher Yu <szufisher@gmail.com>
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<odoo>
<template id="assets_backend" name="web_auto_refresh" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript"
src="/web_auto_refresh/static/src/js/web_auto_refresh.js"/>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save