hpar
7 years ago
committed by
Sylvain LE GAL
7 changed files with 189 additions and 0 deletions
-
69pos_backend_communication/README.rst
-
0pos_backend_communication/__init__.py
-
22pos_backend_communication/__manifest__.py
-
6pos_backend_communication/static/src/css/pos_backend_communication.css
-
42pos_backend_communication/static/src/js/back.js
-
40pos_backend_communication/static/src/js/common.js
-
10pos_backend_communication/views/assets.xml
@ -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 <https://github.com/OCA/pos/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/pos/issues/new?body=module:%20pos_remove_pos_category%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
|||
|
|||
|
|||
Credits |
|||
======= |
|||
|
|||
Contributors |
|||
------------ |
|||
|
|||
* Raphaël Reverdy <raphael.reverdy@akretion.com> |
|||
|
|||
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. |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2017 Akretion (http://www.akretion.com). |
|||
# @author Raphaël Reverdy <raphael.reverdy@akretion.com> |
|||
# 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', |
|||
], |
|||
} |
@ -0,0 +1,6 @@ |
|||
.pos_backend_communication .o_sub_menu { |
|||
display: none !important; |
|||
} |
|||
.pos_backend_communication #oe_main_menu_navbar { |
|||
display: none !important; |
|||
} |
@ -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, |
|||
}; |
|||
|
|||
}); |
@ -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, |
|||
}; |
|||
}); |
@ -0,0 +1,10 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<template id="assets_backend" name="backend" inherit_id="web.assets_backend"> |
|||
<xpath expr="." position="inside"> <!-- both back and POS --> |
|||
<script type="text/javascript" src="/pos_backend_communication/static/src/js/common.js"></script> |
|||
<script type="text/javascript" src="/pos_backend_communication/static/src/js/back.js"></script> |
|||
<link rel="stylesheet" href="/pos_backend_communication/static/src/css/pos_backend_communication.css"/> |
|||
</xpath> |
|||
</template> |
|||
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue