Skip to main content

How to Add Custom Fields to Product in Odoo

Odoo is a powerful open source platform that enables businesses to create custom applications tailored to their specific needs. One of the great features of Odoo is the ability to add custom fields to products. This allows businesses to track additional information about their products, such as supplier details or manufacturing data. In this article, we’ll show you how to add custom fields to products in Odoo.

Adding custom fields to products in Odoo is simple and only requires a few steps.

  • First, you’ll need to inherit product models (product.product and product.template).
  • Next, you’ll need to add the custom fields to your product template.
  • Finally, you’ll need to add the fields to a product’s view such as form, tree, or bankan view.
class ShopeeProduct(models.Model):
    _inherit = 'product.product'

    shopee_variation_id = fields.Char(string='Shopee Variation ID')

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

    shopee_product_id = fields.Char(string='Shopee Product ID')

Tree view:

<record model="ir.ui.view" id="view_shopee_variantions_tree_inherit">
    <field name="name">product.product.tree.inherit</field>
    <field name="model">product.product</field>
    <field name="inherit_id" ref="product.product_product_tree_view"/>
    <field name="arch" type="xml">
        <xpath expr="//tree//field[@name='uom_id']" position="after">
            <field name="shopee_variation_id"/>
        </xpath>
    </field>
</record>

Form view:

 <record model="ir.ui.view" id="view_product_form_shopee_inherit">
    <field name="name">product.template.common.form.shopee.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='general_information']//group[@name='group_general']/field[@name='barcode']"
               position="after">
            <field name="shopee_product_id"/>
        </xpath>
    </field>
</record>

By continuing to use the site, you agree to the use of cookies.