Odoo Help

Welcome!

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

0

Trouble getting correct button reference in custom module

By
Ben Olsen
on 5/19/14, 11:40 AM 875 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" />
        </field>
    </record>

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']" ...

0
Eric
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">

    </xpath>

 

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">                   
    </xpath>

 

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

 

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

http://www.w3schools.com/xpath/xpath_syntax.asp

 

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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/19/14, 11:40 AM
Seen: 875 times
Last updated: 3/16/15, 8:10 AM