Introduction
When you need to tweak Odoo to match your client’s unique workflow, custom fields and views become your superpowers. This article walks you step-by-step through creating or customizing Odoo views and fields for a small change or a full-featured module, and making it all seamless in Odoo 18.
Let’s build something practical and fast!
Why Customize Odoo Fields and Views?
Odoo’s standard setup works for most businesses—but every company has its quirks. Whether it’s tracking additional customer info or tailoring forms to match internal lingo, customization ensures Odoo feels built just for you.
Note: Learn how to load models and fields to POS in Odoo 17 to enhance your POS customization capabilities.
Understanding the Structure of Odoo Views
Odoo uses XML to define views:
- Form view: For data input and editing
- Tree view: For listing records
- Kanban view: For workflows (like tasks or opportunities)
Step 1: Create a Custom Module
You should never edit core modules directly. Instead:
- Use scaffold command: odoo-bin scaffold my_custom_module addons
- Define __manifest__.py
- Inherit the model you want to extend
Step 2: Add Custom Fields
Let’s say we’re adding a custom field x_customer_code to res.partner
from odoo import models, fields
class ResPartner(models.Model):
_inherit = ‘res.partner’
x_customer_code = fields.Char(string=”Customer Code”)
Step 3: Extend the Form View
You’ll need to inherit and modify the view via XML:
<odoo>
<data>
<record id=”view_partner_form_custom” model=”ir.ui.view”>
<field name=”name”>res.partner.form.custom</field>
<field name=”model”>res.partner</field>
<field name=”inherit_id” ref=”base.view_partner_form”/>
<field name=”arch” type=”xml”>
<xpath expr=”//field[@name=’name’]” position=”after”>
<field name=”x_customer_code”/>
</xpath>
</field>
</record>
</data>
</odoo>
Step 4: Update Manifest and Security Access
- Add your XML file to the data section of the manifest
- Add a security CSV file:
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_res_partner_custom,access_res_partner_custom,model_res_partner,base.group_user,1,1,1,1
Step 5: Install and Test
- Restart your server
- Update Apps List
- Install your custom module
Check the Contacts app—you should now see the new field on partner forms.
Advanced Tip: Make Field Mandatory or Invisible by Context
x_customer_code = fields.Char(string=”Customer Code”, required=True)
Or hide conditionally:
<field name=”x_customer_code” attrs=”{‘invisible’:[(‘is_company’,’=’,True)]}”/>
Bonus: Add to Tree View for Quick Access
x_customer_code = fields.Char(string=”Customer Code”, required=True)
Or hide conditionally:
<field name=”x_customer_code” attrs=”{‘invisible’:[(‘is_company’,’=’,True)]}”/>
Conclusion
Custom fields and views let you mold Odoo like clay. Once you’ve grasped the basics, the possibilities are endless—from minor tweaks to full module overhauls.
So go ahead—start crafting the perfect UI for your workflow.
Ready to tailor your Odoo exactly how you want it? Book a consultation now and let our experts guide your custom development journey.
Frequently Asked Questions
1. Can I create custom fields from the UI instead of code?
Yes, but only in Studio. For production-grade work, code is more stable.
2. Will my changes break during upgrades?
If done properly in custom modules, no—they remain safe.
3. How do I make a custom field searchable?
Add index=True to the field definition.
4. Can I reorder fields visually in views?
Yes, use xpath in XML to place fields exactly where you want.
5. Do I need to restart Odoo every time?
Yes, for Python changes. But XML view updates only need a refresh.