Skip to Content
Menu
This question has been flagged
2 Replies
3086 Views

im having a hard time understanding _inherit, they said that with _inherit you could override a object , for example res.partner , 

 i have created a new module folder on odoo/addons path. and on my module.py i added the below script

with this python script they said that you should be able to add fields into the res.partner object

 

~SOME OF MY working codes here

.

.

class res_partner(osv.osv)

_inherit='res.partner'

_columns={  my_var:fields.integer('my number'),

}

after updating and upgrading modules in odoo, 

why is it that i cant find the field 'my_var' into the Settings>Database Structure > Models    and search for res.parner > fields 

 

 

Avatar
Discard

hi, Just confirm that you have added your file into __init__.py file.

Best Answer

my_var need to be a string, so your code should be something like:

class res_partner(osv.osv)

_inherit='res.partner'

_columns={  'my_var': fields.integer('my number'),

}

Note that osv.osv has been deprecated in 7.0 use orm.Model instead.

Avatar
Discard
Author

thanks for that info man

Author

im getting NameError: name 'orm' is not defined when i changed osv.osv to orm.Model

Author

in the header im using from openerp.osv import osv,fields do i need to change this one?

Yes you need to change it to openerp.osv import orm, fields. Note that if you take out osv, you might want to search for all osv usages. Common example is use of osv.except_osv which need to be changed to orm.except_orm (same signature just different name).

Best Answer

All the above answers are correct, but perhaps you are forgetting the most important thing: have you restarted your OpenERP server?

Everytime you make a change in your python files, the server has to be restarted, to recompile your python code. If even that doesn't work, remove any .pyc files on your module and then restart your OpenERP server again.
 

Avatar
Discard
Author

thanks it works! by the way when i remove .pyc files it always reappear and why? also what are these .pyc for?

.pyc is the compiled version of your .py file. At run time, .pyc is the file that will be read unless if there is a newer (by timestamp) .py file, in which python will (re-)generate the .pyc file.

.pyc are exactly what @john doe said. if it worked, you might want to mark it as accepted, so that other users may know what is the correct solution for this kind of problem.