Odoo Help


Trouble getting correct button reference in custom module

Ben Olsen
on 5/19/14, 11:40 AM 1,259 views

I'm trying to use a custom module to customize various aspects of the interface, and can't seem to get the reference to a particular button correct. With the "stock" addon installed, the product "Inventory" tab has a section for "Stock and Expected Variations." I can see in the source code that this is added in the file "addons/stock/product_view.xml".

In this view, next to the "Quantity on Hand" (name="qty_available") field, there is a text button called "update" that lets users manually set the quantity available of that product. For our business, we don't want to allow that, so I thought a simple solution would be to hide the "update" button. In the source code, the button has attribute name="%(action_view_change_product_quantity)d", but in my custom module, I can't seem to refer to it with that name.

In my code, when I try to do:

<button name="%(action_view_change_product_quantity)d" position="replace" />

I get an error:

ValueError: No such external ID currently defined in the system: ui_customizations.action_view_change_product_quantity

My module is called ui_customizations, and in my __openerp__.py file I have:

"depends" : ['base', "product", "account", "stock"],

So it should be able to inherit correctly from the stock module. However no matter what I do, I can't seem to hide that update button. Here's my full code from the record level:

    <record id="my_procurement_locations_form" model="ir.ui.view">
        <field name="name">my.product.normal.procurement.locations.inherit</field>
        <field name="model">product.product</field>
        <field name="inherit_id" ref="product.product_normal_form_view"/>
        <field name="arch" type="xml">
            <button name="%(action_view_change_product_quantity)d" position="replace" />

Anybody have any idea what I'm doing wrong?


Comments seem to be not working at the moment, so here's my addition. Thanks to Mertechdata for getting me going in the right direction. There are two things I was still missing after his comment. First, my inherid_id was wrong, and it needed to be:

<field name="inherit_id" ref="stock.view_normal_procurement_locations_form"/>

Second, when referencing another module's ID names, you need to prepend the ID with the module name (otherwise it only looks in the current module:

<xpath expr="//button[@name='%(stock.action_view_change_product_quantity)d']" ...

On 5/19/14, 12:20 PM

You will want to reference it using xpath tags instead of a button tag like this:

    <xpath expr="//button[@name='%(action_view_change_product_quantity)d']" position="replace">



Here is another example where you can navigate down to the elements location on xml file:

    <xpath expr="/form/header/button[@name='copy_quotation']" position="replace">                   


You can also set the buttons invisible attribute to True like this:

    <xpath expr="//field[@name='shop_id']" position="attributes">   
        <attribute name="invisible">True</attribute>                      


A good tutorial using xpath can be found on this website:



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/19/14, 11:40 AM
Seen: 1259 times
Last updated: 3/16/15, 8:10 AM