Skip to Content
Menu
This question has been flagged
8 Replies
12734 Views

I would like to display a field in Form View of the product module, here is the python file (i use odoo 12.):

class ClassProductInherited:
    _inherit = 'product.template'

    file = fields.Char(string="Choose File")

Here is xml code (i use odoo 12.):

<record id="view_product_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_only_form_view"/>
            <field name="arch" type="xml">
                <xpath expr="//page[@name='inventory']/group" position="before">
                    <group col="2" colspan="2">
                        <field name="file"/>
                    </group>
                </xpath>

            </field>
        </record>

When I restart the server, problem is that I have the following error:

File "/home/odoo/models.py", line 1112, in _validate_fields
    raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e)))
odoo.tools.convert.ParseError: "Error while validating constraint

Field `file` does not exist

Error context:
View `product.template.common.form.inherit`
[view_id: 2095, xml_id: module.view_product_form_inherit, model: product.template, parent_id: 402]
None" while parsing /home/omar/odoo/custom-addons/addons12/module/views/views.xml:403, near
<record id="view_product_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_only_form_view"/>
            <field name="arch" type="xml">
                <xpath expr="//page[@name='inventory']/group" position="before">
                    <group col="2" colspan="2">
                        <field name="file"/>
                    </group>
                </xpath>

            </field>
        </record>
Avatar
Discard

Renaming the field name in both .py and .xml files then restart the odoo server, upgrade the module from apps. I hop this will helps.

Best Answer

Your class definition is incorrect..It should be something like this:

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

Make sure you have imported fields, models like this at the start of the .py file like this:

from odoo import fields, models

and properly mention your .py file name inside the __init__.py file in models

Avatar
Discard
Best Answer

Hi, please check your class definition, you missed some arguments

class ClassProductInherited(models.Model):  
   _inherit = 'product.template'

    file = fields.Char(string="Choose File")
Avatar
Discard
Best Answer

Renaming the field name in both .py and .xml files then restart the odoo server, upgrade the module from apps. I hop this will helps.

Avatar
Discard
Best Answer

Hi Ahemd

Import your python module containing the class in the __init__.py,.


Avatar
Discard
Best Answer

Hai,

Check wheather the indentation is correct for the python module...

And then check wheather the module is defined in __init__.py

Thanks...

Avatar
Discard
Best Answer

Check if you import your python module containing the class in the __init__.py, it's a common mistake.

Avatar
Discard
Best Answer

check your model and ensure you have a valid field named file in proper syntax.

Avatar
Discard
Related Posts Replies Views Activity
3
Oct 23
5973
1
Sep 23
1963
1
May 23
1001
2
Apr 23
1374
1
Mar 23
996