Archive for the ‘openerp’ Category

openerp – how to add a custom field to an object

October 4, 2010 15 comments

Adding a custom field to an existing object it’s as easy as the following few lines of code.

Let’s say you want to add a field to partner. Create a file into your module and add the following to it:

from osv import fields,osv

class res_partner(osv.osv):

    _inherit = 'res.partner'

    _columns = {
           'mytext':fields.char('My custom text field',size=64),


Now, if you want to display this field into partner’s view you have to override the form view.

Create a partner_view.xml into your module and add:

<?xml version="1.0" encoding="utf-8"?>
        <record id="mypartner_form" model="ir.ui.view">
            <field name="name">partner.myform</field>
	        <field name="model">res.partner</field>
	        <field name="type">form</field>
	        <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="arch" type="xml">
               <field name="name" position="after">
                    <field name="mytext" />

Then you’ll need to install your module or to upgrade it if already installed.

See openerp docs for further info.

Categories: openerp, openobject, python