[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>
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user