Odoo Help

0

Problem to run javascript code from a server side button

By
Axel Sabotier
on 5/27/14, 11:00 AM 1,723 views

Hi, I'm trying to execute some javascript code.

Javascript file :

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

Thanks to this xml file, i can run my javascript fonction when I click on the menuitem, but it doesn't work with the button.

XML file :

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>

<!-- Action to perform -->        


        <record id="view_order_form_button_action" model="ir.actions.client">
            <field name="name">Button Action</field>
            <field name="tag">edit.action</field>
        </record>

<!-- Button linked to the action-->


        <record id="view_order_form_button" model="ir.ui.view">
            <field name="name">view.order.form.button</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                <data>
                    <field name="name" position="after">
                        <button  string="Edit" name="view_order_from_button_action" type="action"/>
                    </field>
                </data>
           </field>
        </record>


<!-- Menuitem linked to the action-->       

          <menuitem action="view_order_form_button_action" id="view_order_form_menu" parent="base.menu_sales"/>

    </data>
</openerp>

It doesn't give any error, and the javascript isn't executed.

What is wrong with this code ?

0
Ben Olsen
On 8/11/14, 12:15 PM

It's been a while since you asked this, but you were so close, so hopefully you'll still see this. You just need to change your button name to a reference, since it's an action. (I have no idea why Odoo doesn't just handle this internally).

<button  string="Edit" name="%(view_order_from_button_action)d" type="action"/>

I did something just like this from the tutorial, and it works fine once the button reference is correct.

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.

Register

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

1 follower(s)

Stats

Asked: 5/27/14, 11:00 AM
Seen: 1723 times
Last updated: 3/16/15, 8:10 AM