Odoo Help

Welcome!

This community 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.

1

cannot call custom JS from inherited qweb template

By
Peter Nietz
on 4/10/14, 9:09 AM 4,774 views

I try to call a JS function from my qweb inherited template via:

 <tr t-extend="ListView.row">
      <t t-jquery="td" t-operation="replace">
     [...]
      <t t-set="test" t-value="value_check(column.id, record.get(column.id))"/>

But I allways get the Error:

   Error: QWeb2 - template['ListView.rows']: 
   Runtime Error: Error: QWeb2 - template['ListView.row']: 
   Runtime Error: TypeError: dict.value_check is not a function

without the function call the extended template works fine. So the JS function cannot be found. First I tried this JS code for my function:

openerp.my_module = function(instance){
  var module = instance.web // loading the namespace of the 'sample' module

  module.View.include({
      value_check: function(key, value){
          console.log(key + ": " + value);
          return true;
      },        
  });
};

and then also

openerp.my_module = function(instance){
  var module = instance.web; // loading the namespace of the 'sample' module

  var _super_ = module.View.prototype.value_check;

  module.View.prototype.value_check = function(key, value){
       console.log(key +': '+value);
       _super_.call(this);
      return true;
  };
};

any suggestions? Could it be its because of the inherited tempate? But I can call stuff like render_cell from the web module js. It even doesn't work if I put the check_value into the view_list.js of the web module.

0
Peter Nietz
On 4/11/14, 7:23 AM

OK, I solved it: The class I was extending was wrong.

openerp.my_module = function(instance){
    var module = instance.web.list  // loading the namespace of  'web.list' 

    module.Column.include({         // include to  'web.list.Column' class
        value_check: function(key, value){
           console.log(key + ": " + value);
           return true;
        },        
    });
};

Then I have to call my function via:

  <t t-set="test" t-value="column.value_check(column.id, record.get(column.id))"/>

...and it works perfectly.

0

Brett Lehrer

--Brett Lehrer--
1252
| 5 4 8
Milwaukee, United States
--Brett Lehrer--
Director of IT and open source enthusiast.
Brett Lehrer
On 4/10/14, 1:54 PM

Is "custom_list" the name of your module folder? That would prevent the JS from loading. Either rename the module or edit the JS to say "openerp.web_module_name".

yes it is the module name, but it doesn't work. I edited my post so its not confusing, I hope. I even tried to add the function to the web module itself but still the same error. Could it be because I extended the ListView.row template?

Peter Nietz
on 4/10/14, 2:34 PM

thx ... u put me on the right track

Peter Nietz
on 4/11/14, 7:25 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 4/10/14, 9:09 AM
Seen: 4774 times
Last updated: 3/16/15, 8:10 AM