Odoo Help


Problem to run javascript code from a server side button

Axel Sabotier
on 5/27/14, 11:00 AM 1,605 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"?>

<!-- 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>

<!-- 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">
                    <field name="name" position="after">
                        <button  string="Edit" name="view_order_from_button_action" type="action"/>

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

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


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

What is wrong with this code ?

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.

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


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)


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