Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to inherits views and replace any fields in views in Odoo?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 6.48k
    Comment on it

    In Odoo first, we create existing modules and then we inherits the views in modules. Like first, we install the accounting modules in database and then inherits the account modules. Object is the account.invoice in existing modules and if user wants to replace any fields after inheriting the views then he can do this by using xpath in modules. Xpath is very useful for views.

    Exmaple:-

    In your .py file use this code show below:

    class account_invoice(osv.Model):
        _inherit = 'account.invoice'   
        _columns = {
            'yourfields': fields.char('yourfields', readonly="True"),
                   }
    account_invoice()

     

    In your .xml file use this code show below:

    <?xml version="1.0" encoding="utf-8"?>
    <openerp>
        <data>
            <record id="invoice_form" model="ir.ui.view">
    		<field name="name">account.invoice.form.inherit</field>
    		<field name="model">account.invoice</field>
    		<field name="inherit_id" ref="account.invoice_form" />
    		<field name="arch" type="xml">
    			<data>
               <!--replace fields like as team_id in your account invoice form-->
                    <xpath expr="//field[@name='team_id']" position="replace">    
                    </xpath>
                    <field name="quantity" position="after">
    		      <field name="yourfields"/>
    		</field>
    
    			</data>
    		</field>
         </record> 
        </data>
    </openerp>

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: