diff --git a/pos_backend_communication/README.rst b/pos_backend_communication/README.rst new file mode 100644 index 00000000..3589138f --- /dev/null +++ b/pos_backend_communication/README.rst @@ -0,0 +1,69 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License + +POS Backend Communication +========================= + +Communicate with the backend from point of sale. + +Common use case: + - a click on a button on the pos opens the backend in a popup to a specific view. + - a click on a button on the backend's view send to pos some interesting data. + +Implementations +--------------- + +pos_backend_partner: select a pos customer from the backend + + +Configuration +============= + +No configuration is needed. + +Developper Guide +================ + +The POS communicate with subpages (popups) with [window.open](https://developer.mozilla.org/docs/Web/API/Window/open) and [window.postMessage](https://developer.mozilla.org/docs/Web/API/Window/postMessage) + +Popups are in not-so-old browsers opened in tabs. + +When a backend page is open, a class is set on body to hide menus. + + +Roadmap +======= + +- Improve origin verificiation +- Try to use frames instead of popups +- Use notifications for supported browsers + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + + +Credits +======= + +Contributors +------------ + +* Raphaël Reverdy + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://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. diff --git a/pos_backend_communication/__init__.py b/pos_backend_communication/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pos_backend_communication/__manifest__.py b/pos_backend_communication/__manifest__.py new file mode 100644 index 00000000..c075a4a0 --- /dev/null +++ b/pos_backend_communication/__manifest__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Akretion (http://www.akretion.com). +# @author Raphaël Reverdy +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "POS Backend Communication", + "summary": "Communicate with odoo's backend from POS.", + "version": "10.0.1.0.0", + "category": "Point of Sale", + "website": "www.akretion.com", + 'author': 'Akretion, Odoo Community Association (OCA)', + "license": "AGPL-3", + "application": False, + 'installable': True, + "depends": [ + "point_of_sale", + ], + "data": [ + 'views/assets.xml', + ], +} diff --git a/pos_backend_communication/static/src/css/pos_backend_communication.css b/pos_backend_communication/static/src/css/pos_backend_communication.css new file mode 100644 index 00000000..992c6eff --- /dev/null +++ b/pos_backend_communication/static/src/css/pos_backend_communication.css @@ -0,0 +1,6 @@ +.pos_backend_communication .o_sub_menu { + display: none !important; +} +.pos_backend_communication #oe_main_menu_navbar { + display: none !important; +} \ No newline at end of file diff --git a/pos_backend_communication/static/src/js/back.js b/pos_backend_communication/static/src/js/back.js new file mode 100644 index 00000000..c995dcd3 --- /dev/null +++ b/pos_backend_communication/static/src/js/back.js @@ -0,0 +1,42 @@ +'use strict'; + +odoo.define('pos_backend_communication.back', function (require) { + var tools = require('pos_backend_communication.tools'); + var ActionManager = require('web.ActionManager'); + var core = require('web.core') + + function is_tied_to_pos() { + return (!!window.opener); + //TODO : add test location.origin + } + + function sendMessage(a) { + //send message to pos + if (is_tied_to_pos()) { + //can only work if the backoffice is opened by the POS + window.opener.postMessage(a, location.origin); + } + } + + if (is_tied_to_pos()) { + //set up action 'act_tell_pos' called by .py + ActionManager.include({ + ir_actions_act_tell_pos: function (action, options) { + sendMessage(action.payload); + } + }); + + //when page is fully loaded + core.bus.on('web_client_ready', null, function () { + //this class hides menus + $('body').addClass('pos_backend_communication'); + }); + } + + return { + 'sendMessage': sendMessage, + 'callbacks': tools.callbacks, + 'is_tied_to_pos': is_tied_to_pos, + }; + +}); \ No newline at end of file diff --git a/pos_backend_communication/static/src/js/common.js b/pos_backend_communication/static/src/js/common.js new file mode 100644 index 00000000..e4b8385d --- /dev/null +++ b/pos_backend_communication/static/src/js/common.js @@ -0,0 +1,40 @@ +'use strict'; + +odoo.define('pos_backend_communication.tools', function (require) { + var translation = require('web.translation'); + var core = require('web.core'); + var _t = translation._t; + var callbacks = {}; + + function dispatchMessageEvent(message) { + //don't be tricked by others sites + if (message.origin !== window.location.origin) { + return console.error('Message comming from untrusted source'); + } + + if (!message.data.type) { + return console.error('Message uncompliant'); + } + + var fun = callbacks[message.data.type]; + if (fun) { + fun(message); + } else if(core.debug) { + console.error('Unkown message type', message.data.type); + } + } + + function open_page(url, msg, identifier) { + var bo = window.open(url, identifier || 'backoffice'); //unique identifier of the 2nd window + if (!bo) { + throw _t("Please authorize popups for this window"); + } + bo.postMessage(msg, window.location.origin); //because backoffice.alert set focus + } + + window.addEventListener('message', dispatchMessageEvent); + return { + 'callbacks': callbacks, + 'open_page': open_page, + }; +}); diff --git a/pos_backend_communication/views/assets.xml b/pos_backend_communication/views/assets.xml new file mode 100644 index 00000000..5c234d5d --- /dev/null +++ b/pos_backend_communication/views/assets.xml @@ -0,0 +1,10 @@ + + + +