diff --git a/addons/point_of_sale/static/src/js/Chrome.js b/addons/point_of_sale/static/src/js/Chrome.js index 633aa2b9936..ba8fae8c759 100644 --- a/addons/point_of_sale/static/src/js/Chrome.js +++ b/addons/point_of_sale/static/src/js/Chrome.js @@ -115,6 +115,7 @@ odoo.define('point_of_sale.Chrome', function(require) { // We can then test PosModel independently from Chrome by supplying // mocked version of these default attributes. const posModelDefaultAttributes = { + env: this.env, rpc: this.rpc.bind(this), session: this.env.session, do_action: this.props.webClient.do_action.bind(this.props.webClient), 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) {