Change one of the OpenERP kernel fields using a custom module

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

Is it possible to change an existing field without making changes to the module that declared it? I would rather make changes using our own module instead of editing the product module itself.

+6
source share
3 answers

It works for me, but I hope someone else knows a cleaner way.

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

 _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 it is because you now have duplication for all other field attributes. If you change the length of the field and then the main module changes the help text, you will still have the old help text. I was hoping there would be some way when the modules load and adjust your parent's field attributes, but I could not find the hooks at the right time.

One change you can make easier is the default value for the field. Just declare a default value for the core module field in your custom module and it will replace the original default value. For example, we changed the default values ​​for sale_delay and produce_delay from the product module .

 _defaults = {'sale_delay': lambda *a: 5, 'produce_delay': lambda *a: 0} 
+4
source

In ODOO, we can change any field attribute using xml.

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

But some case, like an extension of the field size, did not work.

+1
source

You need to inherit the form of the product.

Here you go.

 from openerp.osv import fields, osv class product_product(osv.Model) # <<<v7 _inherit = 'product.product' _columns = { 'loc_rack': fields.char('Rack', size=<your size>), 'loc_row': fields.char('Row', size=<your size>), 'loc_case': fields.char('Case', size=<your size>) } 

In simple words, you just need to override this field and apply changes to the attributes that it will reflect.

0
source

Source: https://habr.com/ru/post/921877/


All Articles