How to make a button that triggers javascript action ? v6



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 : But it doesn't work, and I'm not understanding what I made wrong.

I have the following files :

    ├── web_example.xml  
    ├── static 
                ├── src
                     └── js
                           └── first_module.js 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/", line 180, in dispatch
    response["result"] = method(controller, self, **self.params)
  File "/opt/openerp/server/openerp/addons/web/controllers/", 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/", line 948, in call_common
    return self._call_kw(req, model, method, args, {})
  File "/opt/openerp/server/openerp/addons/web/controllers/", line 962, in _call_kw
    return getattr(req.session.model(model), method)(*args, **kwargs)
  File "/opt/openerp/server/openerp/addons/web/common/openerplib/", line 250, in proxy
    args, kw)
  File "/opt/openerp/server/openerp/addons/web/common/openerplib/", line 117, in proxy
    result = self.connector.send(self.service_name, method, *args)
  File "/opt/openerp/server/openerp/addons/web/common/", line 611, in send
    raise fault

Server Traceback (most recent call last):
  File "/opt/openerp/server/openerp/addons/web/common/", line 592, in send
    result = openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/opt/openerp/server/openerp/", line 360, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/opt/openerp/server/openerp/service/", line 569, in dispatch
  File "/opt/openerp/server/openerp/service/", line 40, in check
    pool = pooler.get_pool(db)
  File "/opt/openerp/server/openerp/", line 50, in get_pool
    return get_db_and_pool(db_name, force_demo, status, update_module)[1]
  File "/opt/openerp/server/openerp/", line 33, in get_db_and_pool
    registry = RegistryManager.get(db_name, force_demo, status, update_module, pooljobs)
  File "/opt/openerp/server/openerp/modules/", line 138, in get
    update_module, pooljobs)
  File "/opt/openerp/server/openerp/modules/", line 160, in new
    openerp.modules.load_modules(registry.db, force_demo, status, update_module)
  File "/opt/openerp/server/openerp/modules/", 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/", 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/", line 193, in load_module_graph
    load_data(module_name, idref, mode)
  File "/opt/openerp/server/openerp/modules/", line 92, in <lambda>
    load_data = lambda *args: _load_data(cr, *args, kind='data')
  File "/opt/openerp/server/openerp/modules/", line 138, in _load_data
    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
  File "/opt/openerp/server/openerp/tools/", line 997, in convert_xml_import
  File "/opt/openerp/server/openerp/tools/", line 890, in parse
    self._tags[rec.tag](, rec, n)
  File "/opt/openerp/server/openerp/tools/", 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 ?


1 Answer
Best Answer

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 :/


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