2
votes

I'm adding a custom string field (stock_value) to the 'product.supplierinfo' module in Odoo enterprise 11 but I can't get it to display the label correctly.

I inherited the module and then added a new field to the module and to the view trough xpath.

Problem: the string related to the new field is not shown.

Module:

class class_name(models.Model):
    _inherit                        = 'product.supplierinfo'
    stock_value                     = fields.Integer(string="Stock")

View:

<!-- Stock value in the vendors -->
<record id="view_product_product_supplierinfo_form_view" model="ir.ui.view">
    <field name="name">product.supplierinfo.product.form</field>
    <field name="model">product.supplierinfo</field>
    <field name="inherit_id" ref="product.product_supplierinfo_form_view"/>
    <field name="arch" type="xml">
    <xpath expr="//field[@name='price']" position="after">
        <field name="stock_value" />
    </xpath>
    </field>
</record>

Result: as you can see theres a zero bellow the price value but the string label 'Stock' is not shown.

enter image description here

Other thing is tried:

Adding the next code:

<separator />
<label for="stock_value" string="Stock Value"/>

Gives me

enter image description here

Putting the field inside a group gives me

enter image description here

I also tried changing the position to 'before' in this last view but I cannot manage to make it look as it should. I tried using @string but that no longer works.

Thank you in advantage for your help.

1

1 Answers

3
votes

The problem is that the field price is inside a div container, so you have to put your field after this div (which is the parent of the field price in the DOM). Thus, you have to tell xpath that you want to put your field after the DOM parent of the field price, not just after the field as you have in your code. Depending on the style you are looking for, you can select any of the following options:

Option 1 (you could add class="oe_inline to your field too"):

<!-- Stock value in the vendors -->
<record id="view_product_product_supplierinfo_form_view" model="ir.ui.view">
    <field name="name">product.supplierinfo.product.form</field>
    <field name="model">product.supplierinfo</field>
    <field name="inherit_id" ref="product.product_supplierinfo_form_view"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='price']/.." position="after">
            <label for="stock_value"/>
            <div>
                <field name="stock_value"/>
            </div>
        </xpath>
    </field>
</record>

Option 2:

<!-- Stock value in the vendors -->
<record id="view_product_product_supplierinfo_form_view" model="ir.ui.view">
    <field name="name">product.supplierinfo.product.form</field>
    <field name="model">product.supplierinfo</field>
    <field name="inherit_id" ref="product.product_supplierinfo_form_view"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='price']/.." position="after">
            <field name="stock_value"/>
        </xpath>
    </field>
</record>