How To Add New Fields and Views To Existing Module (APP)

Let’s talk about How To Add New Fields and Views To the Existing Module (APP)  in Odoo ERP. You can also change the properties of the existing field with bonus part.

Custom_addons

Add this path on odoo.conf file
addons_path = C:\public\Ravi Gupta\odoo15.0\addons,custom_addons

Odoo_customization

__init__.py
from . import models
__manifest__.py
# -*- coding: utf-8 -*-
{
'name': "Odoo_customization",
'version' : "0.0.1",

'summary': """This is for Customizing Existing Module""",
'sequence' : -104,

'depends': ['sale'],

'data': [
'views/sales_quot_view.xml',
],
# only loaded in demonstration mode
'demo': [
],
'installable': True,
'application': True,
'auto_install': False,
'license' : 'LGPL-3',
}

models

__init__.py
from . import sales_quot
Open Your Sales Module just Click on Create Quotation

Just put your mouse cursor on the customer, and you get all the details about your field. 

Make sure you activate the developer mode.

sales_quot.py
from odoo import models, fields

class SaleOrder(models.Model):
_inherit = 'sale.order'

sale_new_field = fields.Char(string='Sale New Field')

views

form view_external Id
tree_external_id
sales_quot_view.xml
<odoo>
<!-- This is Inherit form Views-->
<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.order.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="sale_new_field"/>
</xpath>
</field>
</record>
<!-- This is Inherit Tree Views-->
<record id="view_order_tree_inherit" model="ir.ui.view">
<field name="name">sale.order.inherit.tree</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_quotation_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="sale_new_field"/>
</xpath>
</field>
</record>
</odoo>
Output in form
Output in Tree/list view
odoo_tree_view
Bonus(Field properties)
 <!--            Add a new field -->
<field name="partner_id" position="after">
<field name="sale_new_field"/>
</field>
<!-- OR -->
<xpath expr="//field[@name='partner_id']" position="after">
<field name="sale_new_field"/>
</xpath>

<!-- Hide/Remove the existing Field(Hiding Customer) M1-->

<xpath expr="//field[@name='partner_id']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>

<!-- Hide/Remove the existing Field(Hiding Customer) M2-->

<field name="partner_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>

<!-- Customer Rename to vendor with existing Field Properties(Change Customer to vendor)-->

<field name="partner_id" position="attributes">
<attribute name="string">Vendor</attribute>
</field>

<!-- Change the properties of Exiting Field (Now payment term is required field)-->

<field name="payment_term_id" position="attributes">
<attribute name="required">1</attribute>
</field>

<!-- NonEditable field(Quotation Date)-->

<field name="date_order" position="attributes">
<attribute name="readonly">1</attribute>
</field>
</field>
</record>

Leave a Comment

Your email address will not be published. Required fields are marked *