summaryrefslogtreecommitdiff
path: root/addons/point_of_sale/static/src/js/models.js
diff options
context:
space:
mode:
authorAntoine Prieels <anp@odoo.com>2020-07-08 12:45:10 +0000
committerAntoine Prieels <anp@odoo.com>2020-07-08 12:45:10 +0000
commit5bd8e6e0a8d5cecedfdec8be0b7f314c0f5f3648 (patch)
tree3f86ffad585e3b86e12ca4031df2e10e34d80c34 /addons/point_of_sale/static/src/js/models.js
parentdd8a6b8a8299afaac699d04f2ed886ff85c685fe (diff)
[IMP] point_of_sale: Call services from posmodel
Add the possibility to call services from posmodel. At the moment, this is needed to call the `iot_longpolling` service from `DeviceProxy`. closes odoo/odoo#54229 Related: odoo/enterprise#11708 Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Diffstat (limited to 'addons/point_of_sale/static/src/js/models.js')
-rw-r--r--addons/point_of_sale/static/src/js/models.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js
index e0777105b7d..8f6e419f557 100644
--- a/addons/point_of_sale/static/src/js/models.js
+++ b/addons/point_of_sale/static/src/js/models.js
@@ -36,6 +36,7 @@ exports.PosModel = Backbone.Model.extend({
var self = this;
this.flush_mutex = new Mutex(); // used to make sure the orders are sent to the server once at time
+ this.env = this.get('env');
this.rpc = this.get('rpc');
this.session = this.get('session');
this.do_action = this.get('do_action');
@@ -1241,6 +1242,29 @@ exports.PosModel = Backbone.Model.extend({
}
},
+ /**
+ * Directly calls the requested service, instead of triggering a
+ * 'call_service' event up, which wouldn't work as services have no parent
+ *
+ * @param {OdooEvent} ev
+ */
+ _trigger_up: function (ev) {
+ if (ev.is_stopped()) {
+ return;
+ }
+ const payload = ev.data;
+ if (ev.name === 'call_service') {
+ let args = payload.args || [];
+ if (payload.service === 'ajax' && payload.method === 'rpc') {
+ // ajax service uses an extra 'target' argument for rpc
+ args = args.concat(ev.target);
+ }
+ const service = this.env.services[payload.service];
+ const result = service[payload.method].apply(service, args);
+ payload.callback(result);
+ }
+ },
+
electronic_payment_interfaces: {},
format_currency: function(amount, precision) {