1

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?

KbiR
  • 4,047
  • 6
  • 37
  • 103
Cleber Goncalves
  • 1,936
  • 3
  • 18
  • 23

4 Answers4

2

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.

Veikko
  • 3,372
  • 2
  • 21
  • 31
  • This worked. Would you have any reference document on how to find the 'correct base form'? – Cleber Goncalves May 08 '18 at 05:17
  • Actually you have a very good question. I do not have any reference document. I have searched for the standard_price and found the base structure for the form and inherited from that. I totally agree that we should have Odoo documentation about this. It would make life a bit easier. – Veikko May 08 '18 at 19:58
1

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()
Kenly
  • 24,317
  • 7
  • 44
  • 60
  • That depends on how you use products in Odoo. You always should consider if the fields belong to the template or the variant. This question should be answered by the questioner first. – CZoellner May 07 '18 at 09:27
  • @CZoellner He used `product_template_form_view`. – Kenly May 07 '18 at 10:18
  • Yes i'm not saying you answer is wrong, but the question is not fully clear ;-) – CZoellner May 07 '18 at 14:52
  • Turns out there were 3 mistakes on my code, was using the 'variants' product with the 'product' database model, was inheriting from the wrong form and had issues when displaying the field due to the nature of 'standard_price' as pointed by @Veikko on the accepted answer. – Cleber Goncalves May 08 '18 at 05:22
  • @CZoellner Yes I agree with that, and thank you for your comment. – Kenly May 08 '18 at 08:00
  • 1
    @CleberGoncalves I posted this As your question was not clear enough to know what you want really to do and I am glad that you found a good answer to your question. – Kenly May 08 '18 at 08:05
0

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’,
    ]
    ...
}
travisw
  • 2,052
  • 1
  • 14
  • 27
0

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>