Odoo Help

0

Shortcut in ODOO 9

By
sridhar
on 10/23/15, 11:57 AM 878 views

In previous version this js is running but in ODOO 9 it is not working, kindly upgrade this to ODOO 9

openerp.sample_report = function(instance, local) {

var _t = instance.web._t,

_lt = instance.web._lt;

var QWeb = instance.web.qweb;

var ctrl_count = 0;

$.ctrl_bind = function(key, namespace, callback, args) {

var ev = 'keydown.'+namespace;

$(document).on(ev, function(e) {

if(!args) args=[]; // IE barks when args is null

console.log(e.keyCode)

if((e.keyCode == key.charCodeAt(0) || e.keyCode == key) && e.ctrlKey) {

callback.apply(this, args);

return false;

}

});

};

$.ctrl_unbind = function(name) {

var ev = 'keydown.'+name;

$(document).off(ev);

};

instance.web.form.WidgetButton.include({

start: function() {

var self = this;

this._super.apply(this, arguments);

var context = this.build_context().eval();

if(context.shortcut != undefined){

ctrl_count++;

this.ctrl_count = ctrl_count;

$.ctrl_bind(context.shortcut, this.ctrl_count, function() {

alert(1);//for test

self.on_click();//could be used execute_action() too

});

}

},

destroy: function() {

$.ctrl_unbind(this.ctrl_count);

this._super.apply(this, arguments);

},

});

}

1

Axel Mendoza

--Axel Mendoza--
11831
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 10/23/15, 12:53 PM

This should be enough to get it working on Odoo v9 JS layer:

odoo.define('module.sample_report', function (require) {
"use strict";

var core = require('web.core');
var form_widgets = require('web.form_widgets');

var _t = core._t;
var _lt = core._lt;
var QWeb = core.qweb;
var Class = core.Class;

var ctrl_count = 0;

$.ctrl_bind = function(key, namespace, callback, args) {
var ev = 'keydown.'+namespace;
$(document).on(ev, function(e) {
if(!args) args=[]; // IE barks when args is null
console.log(e.keyCode)
if((e.keyCode == key.charCodeAt(0) || e.keyCode == key) && e.ctrlKey) {
callback.apply(this, args);
return false;
}
});
};

$.ctrl_unbind = function(name) {
var ev = 'keydown.'+name;
$(document).off(ev);
};

form_widgets.WidgetButton.include({
start: function() {
var self = this;
this._super.apply(this, arguments);
var context = this.build_context().eval();
if(context.shortcut != undefined){
ctrl_count++;
this.ctrl_count = ctrl_count;
$.ctrl_bind(context.shortcut, this.ctrl_count, function() {
alert(1);//for test
self.on_click();//could be used execute_action() too
});
}
},
destroy: function() {
$.ctrl_unbind(this.ctrl_count);
this._super.apply(this, arguments);
},
});

});

Also I notice that there is a compatibility layer to match the old way of work with js

Axel Mendoza
on 10/23/15, 12:58 PM

Thank you Axel, now it is working fine.

sridhar
on 10/23/15, 11:58 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

Asked: 10/23/15, 11:57 AM
Seen: 878 times
Last updated: 10/23/15, 11:57 PM