1
votes

I want to add a couple of extra fields to the product form, right after 'standard_price'.

I created a view that inherits from "product.product_template_form_view" and added my fields there:

<field name="standard_price" position="after">
        <field name="my_field" />
</field>

I then restart odoo updating the module, but I don't see my new fields when I call the product form.

The fields appear on the database model (created inherited models also), but not on the user interface.

What I'm missing here?

4
On what model did you add fields? Do you understand Odoos concept of product templates and variants?CZoellner
@CZoellner Not sure I understand it fully, would you have any references?Cleber Goncalves
There already was a question about it :-)CZoellner

4 Answers

2
votes

Check these things:

  • Inherited from correct base form product.template.common.form
  • Make sure you are looking at correct form for product.template (Product), not product.product (Product Variant).
  • Do you see the input field without caption in edit mode? If this is the case, you can have broken structure in the html level. Next bullet will solve this.
  • Standard_price field has unique html structure because it can have unit of measure (uom) connected to it. Try connecting to simple field or use the container div standard_price_uom for connection, see template code below.

Template code for working view with a new field after standard_price_uom div:

<div name='standard_price_uom' position="after">
  <field name="my_field" />
</div>

If these does not help, please provide whole view definition.

1
votes

Make sure you use the correct model. Use product.template instead of product.product.

<record id="product_template_form" model ="ir.ui.view">
    <field name="name">product.template.form</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_form_view" />
    <field name="arch" type="xml">
        <field name="standard_price" position="after">
            <field name="my_field"/>
        </field>
    </field>
</record>

...

class ProductTemplate(models.Model):
    _inherit = "product.template"

    my_field = fields.Char()
0
votes

Make sure you have added your XML file into your module’s __manifest__.py file. Odoo only pulls in XML from files that you tell it to.

You can see examples of this on any core modules. See sale/__manifest__.py for an example.

On your module, it would be something like this:

{
    ...
    ‘data’: [
        ‘views/form/form_product.xml’,
    ]
    ...
}
0
votes

I have tested it in Odoo 12.

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="view_product_template_common_form_inherit" model="ir.ui.view">
        <field name="name">product.template.common.form.inherit</field>
        <field name="model">product.template</field>
        <field name="inherit_id" ref="product.product_template_form_view"/>
        <field name="arch" type="xml">
            <xpath expr="//div[@name='standard_price_uom']" position="after">
                <label for="my_field" string="My Field"/>
                <div>
                    <field name="my_field"/>
                </div>
            </xpath>
        </field>
    </record>
</odoo>