Skip to Content
Menu
This question has been flagged
1 Reply
20871 Views

Hi,

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 :

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

__init__.py is empty

__openerp__.py

 {
     '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'],
 }

web_example.xml

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

first_module.js

 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
    security.check(db,uid,passwd)
  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
    obj.parse(doc.getroot())
  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 ?

Thanks.

Avatar
Discard
Author 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"/>    
            </form>
        </field>
 </record>

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

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

and finally static/src/js/function.js

    openerp.web_example = function(openerp) {
      openerp.web.form.widget.add('test','openerp.web.form.test');


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

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

       },

       start: function() {
             console.log('START');   
             $('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.

Avatar
Discard

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.

Eg:

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

Related Posts Replies Views Activity
1
Mar 21
4010
1
Jul 17
2822
3
Mar 15
8898
0
Dec 24
729
0
Mar 24
675