Odoo Help


How to get context value from JS to Python function in ODOO

on 10/4/15, 9:35 AM 4,158 views

I creating web keyboard shortcut module, for ex. In my form i having a print button, In this button is calling a particular report, now I need to call ctrl +U to call that function. here function is calling well but ids getting none only. how to get a ids value, If I give in Print click means ids has some value.  Here is my code.

$.ctrl('H', function() {

var self = this;

return new instance.web.Model('sample.table').call('read', [[self.id], new instance.web.CompoundContext()])


var self = this;

return new instance.web.Model('sample.table').call('print_quotation',[[self.ids]])



// window.print();



Axel Mendoza

--Axel Mendoza--
| 7 8 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 and how

Reach me at aekroft@gmail.com

Axel Mendoza
On 10/5/15, 1:55 AM

Here is how I suggest you to solve the problem. The idea is attach the shortcut to the button to be able to execute the button click when the shortcut combination is pressed. Using the following code in a js file loaded in a module(as example for @srihar there is a module definition of the js file for module sample_report, you could use the bold marked text in your own module if you like)

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
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;

start: function() {
var self = this;
this._super.apply(this, arguments);
var context = this.build_context().eval();
if(context.shortcut != undefined){
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() {
this._super.apply(this, arguments);

To be able to use that extension you need to define your button with a context that contains a shortcut key, for example for clic the following button using the shortcut "ctrl + i" you need to define:

<button name="print_quotation" string="Print" type="object" context="{'shortcut': 'I'}"/>

Note that the value of the key shortcut in the context need to be uppercased

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.


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)


Asked: 10/4/15, 9:35 AM
Seen: 4158 times
Last updated: 10/5/15, 11:49 AM