Odoo Help


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.


How to make a button that triggers javascript action ? v6

on 3/4/13, 6:18 AM 7,606 views


I'm new in OpenERP web module development and I'm currently trying to make a simple module that just display a button, and if I clic the button I want javascript to write a message in the developper console of my browser.

I am following a tutorial : doc.openerp.com/trunk/developers/web/module/ But it doesn't work, and I'm not understanding what I made wrong.

I have the following files :

    ├── __init__.py
    ├── __openerp__.py
    ├── web_example.xml  
    ├── static 
                ├── src
                     └── js
                           └── first_module.js

__init__.py is empty


     'name': "Web Example",
     'description': "Basic example of a (future) web module",
     'category': 'Hidden',
     'depends': ['web'],
   'data': ['web_example.xml'],
     'js': ['static/src/js/first_module.js'],


<?xml version="1.0" encoding="utf-8"?>
        <record model="ir.actions.client" id="action_client_example">
            <field name="name">Example Client Action</field>
            <field name="tag">example.action</field>
        <menuitem action="action_client_example"


 openerp.web_example = function (instance) {
    instance.web.client_actions.add('example.action', 'instance.web_example.action');
    instance.web_example.action = function (parent, action) {
        console.log("Executed the action", action);

According to the tutorial, this code should make a button in the menu, and if you click the button you get a message in the console.

My problem is that when I try to upgrade my module i get errors :

    AssertionError: No window action defined for this id action_client_example !
Verify that this is a window action or add a type argument.

And here is the complete log :

OpenERP Server Error
Client Traceback (most recent call last):
  File "/opt/openerp/server/openerp/addons/web/common/http.py", line 180, in dispatch
    response["result"] = method(controller, self, **self.params)
  File "/opt/openerp/server/openerp/addons/web/controllers/main.py", line 1004, in call_button
    action = self.call_common(req, model, method, args, domain_id, context_id)
  File "/opt/openerp/server/openerp/addons/web/controllers/main.py", line 948, in call_common
    return self._call_kw(req, model, method, args, {})
  File "/opt/openerp/server/openerp/addons/web/controllers/main.py", line 962, in _call_kw
    return getattr(req.session.model(model), method)(*args, **kwargs)
  File "/opt/openerp/server/openerp/addons/web/common/openerplib/main.py", line 250, in proxy
    args, kw)
  File "/opt/openerp/server/openerp/addons/web/common/openerplib/main.py", line 117, in proxy
    result = self.connector.send(self.service_name, method, *args)
  File "/opt/openerp/server/openerp/addons/web/common/http.py", line 611, in send
    raise fault

Server Traceback (most recent call last):
  File "/opt/openerp/server/openerp/addons/web/common/http.py", line 592, in send
    result = openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/opt/openerp/server/openerp/netsvc.py", line 360, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/opt/openerp/server/openerp/service/web_services.py", line 569, in dispatch
  File "/opt/openerp/server/openerp/service/security.py", line 40, in check
    pool = pooler.get_pool(db)
  File "/opt/openerp/server/openerp/pooler.py", line 50, in get_pool
    return get_db_and_pool(db_name, force_demo, status, update_module)[1]
  File "/opt/openerp/server/openerp/pooler.py", line 33, in get_db_and_pool
    registry = RegistryManager.get(db_name, force_demo, status, update_module, pooljobs)
  File "/opt/openerp/server/openerp/modules/registry.py", line 138, in get
    update_module, pooljobs)
  File "/opt/openerp/server/openerp/modules/registry.py", line 160, in new
    openerp.modules.load_modules(registry.db, force_demo, status, update_module)
  File "/opt/openerp/server/openerp/modules/loading.py", line 334, in load_modules
    processed = load_marked_modules(cr, graph, states_to_load, force, status, report, loaded_modules)
  File "/opt/openerp/server/openerp/modules/loading.py", line 253, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules)
  File "/opt/openerp/server/openerp/modules/loading.py", line 193, in load_module_graph
    load_data(module_name, idref, mode)
  File "/opt/openerp/server/openerp/modules/loading.py", line 92, in <lambda>
    load_data = lambda *args: _load_data(cr, *args, kind='data')
  File "/opt/openerp/server/openerp/modules/loading.py", line 138, in _load_data
    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
  File "/opt/openerp/server/openerp/tools/convert.py", line 997, in convert_xml_import
  File "/opt/openerp/server/openerp/tools/convert.py", line 890, in parse
    self._tags[rec.tag](self.cr, rec, n)
  File "/opt/openerp/server/openerp/tools/convert.py", line 632, in _tag_menuitem
    "Verify that this is a window action or add a type argument." % (a_action,)
AssertionError: No window action defined for this id action_client_example !
Verify that this is a window action or add a type argument.

So my question is What am I doing wrong ? Is there another way to just get a button that trigger javascript action ?


On 3/11/13, 11:37 AM

Solution :

In web_example.xml :

 <record model="ir.ui.view" id="test_form_view">
        <field name="name">test.form</field>
        <field name="model">test</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="test">
                <field name="numero"  widget="test"/>    

Then in static/src/xml create a qweb file : test.xml

 <div t-name="test_button" t-attf-class="base #{cls}" class="oe_web_example">  
    <button name="dosomething" type="object" id="bstart">start</button>

and finally static/src/js/function.js

    openerp.web_example = function(openerp) {

    openerp.web.form.test = openerp.web.form.FieldChar.extend(
       template: 'test_button',

       init: function () {
                 this._super.apply(this, arguments);
                 this._start = null;


       start: function() {
             $('button#bstart').click(this.myfunction);  //link button to function  

        myfunction: function() {
              //DO WHAT YOU WANT

You have created a widget based on a fieldchar which displays a button. This button is linked to a javascript function.

Good, but your example is not complete and don't work for me :/

on 6/24/13, 7:03 AM

Hi Team,

I want to do some validation using java script in OpenERP7.


I have a form view and it contains qty and pending_qty fields. If user entered qty is greater than pending_qty i want to show a error using java script.

Is it possible and how can i achieve this ? Kindly help me..Thanks in advance

on 9/20/13, 2:15 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

2 follower(s)


Asked: 3/4/13, 6:18 AM
Seen: 7606 times
Last updated: 6/16/16, 2:21 AM