Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Adding a field to an existing module using Inheritance in OpenERP 6.1

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 734
    Comment on it

    To add a new field to an existing module, the best practice is to create a new module that inherits the model you want this field to add in. And your module will depend on the required module.

    For example adding field cartage to account.invoice model, I created a module called invoice_cartage:

    inheritance.py:

    from osv import fields, osv
    class invoice_cartage(osv.osv):
        _name='account.invoice'
        _inherit='account.invoice'
        _columns={
                   'cartage':fields.float('Cartage',readonly=False),       
                  }
    invoice_cartage()
    

    inheritance_view.xml:

    <?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>
                                <field name="labour" position="after">
                                <field name="cartage"/>
                                </field>
                         </data>
                         </field>
                 </record>
                 <record id="invoice_tree" model="ir.ui.view">
                         <field name="name">account.invoice.tree.inherit</field>
                         <field name="model">account.invoice</field>
                         <field name="inherit_id" ref="account.invoice_tree" />
                         <field name="arch" type="xml">
                         <data>
                              <field name="amount_untaxed" position="after">
                              <field name="cartage" sum="Cartage Amount"/>
                              </field>
                         </data>
                         </field>
                 </record>
            </data>
    </openerp>
    

    Use ref attribute whenever using inheritance. This is the view id of the view to inherit from.

    Note position attribute. You need to mention where you want to place this field on the view, whether after a field or before. Set postion=after/before accordingly with the field of the base view.

    Thats all.

 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: