Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying one of OpenERP's core fields using a custom module

Tags:

odoo

openerp

Sometimes our OpenERP users want to make a small change to a field in a core OpenERP module. For example, they want the product screen's Rack, Row, and Case fields to be longer than 16 characters.

Can I change an existing field without making changes to the module that declared it? I'd rather make the changes using our own custom module, instead of editing the product module itself.

like image 897
Don Kirkby Avatar asked Aug 01 '12 18:08

Don Kirkby


2 Answers

I've got this working, but I'm hoping that someone else knows a cleaner way.

You can inherit the core module's class in your custom module, and then just declare a new field with the same name as the one you want to change. Essentially, just copy the field declaration from the core module, paste it into your custom module, and then make the changes you want. For example, our product_notes module widened the Rack, Row, and Case fields to 255 from the product module's 16.

_columns = {'loc_rack': fields.char('Rack', size=255),
            'loc_row': fields.char('Row', size=255),
            'loc_case': fields.char('Case', size=255)}

The reason I don't like this is that you now have duplication for all the other attributes of the field. If you change the field length, and then the core module changes the help text, you will still have the old help text. I was hoping that there would be some way when the modules are loading to go in and adjust the field attributes of your parent, but I couldn't find any hooks at the right time.

One change that you can make more easily is the default value of a field. Just declare a default value for a core module's field in your custom module, and it will replace the original default. For example, we changed the defaults for sale_delay and produce_delay from those in the product module.

_defaults = {'sale_delay': lambda *a: 5,
             'produce_delay': lambda *a: 0}
like image 109
Don Kirkby Avatar answered Nov 06 '22 00:11

Don Kirkby


In ODOO we can change any attribute of a field using xml.

            <field name="loc_rack" position="attributes">
                <attribute name="string">Axis</attribute>
            </field>

But some case like extending the size of a field its failed.

like image 21
Deviprasad Avatar answered Nov 06 '22 02:11

Deviprasad