How do I make a class (that already exist) inherit another class?

1.4k views Asked by At

For example class res.partner. I want res.partner to inherit class A. How do I do that?

I don't think this will work:

class custom_res_partner(osv.osv):

    _name           = "res.partner"
    _inherit        = "A"

custom_res_partner()
3

There are 3 answers

0
Andrius On BEST ANSWER

If model is already present and you want it to inherit another model, it should be done like this:

class custom_res_partner(osv.osv):
    _name = "res.partner"
    _inherit = ['res.partner', 'A']

_name part is important here, with it Odoo knows which model inherits from which. in _inherit you also need to specify res.partner, because you are extending this model.

1
Emipro Technologies Pvt. Ltd. On
class custom_res_partner(osv.osv):

    _name           = "custom.res.partner"    # New Model will be created
    _inherit        = "A"   # Base class 

custom_res_partner()

It will create new model(table) which have all the properties of it's base class according to inheritance rules. Don't use the res.partner because this model is already there.

4
Gopakumar N G On
# odoo-8
from openerp import fields, models, api, _
class res_partner(models.Model):
    _inherit = "A"

EDIT: (This is for odoo version 8) Create a new module and inherit the model A in a python file in the module. For creating a new module, refer to Build an Odoo module