4

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()
William Wino
  • 3,599
  • 7
  • 38
  • 61

3 Answers3

2

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.

Andrius
  • 19,658
  • 37
  • 143
  • 243
1
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.

1
# 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

Gopakumar N G
  • 1,775
  • 1
  • 23
  • 40
  • What if I don't want to edit the original file? I want it to inherit the other model without even touching the original source code. – William Wino Jun 22 '15 at 06:24
  • I don't think you get my question. I don't want to create a new module. I want to make the preexisting `res.partner` inherit `A` without editing the original source code. – William Wino Jun 22 '15 at 07:39
  • @William what did you meant by 'without editing the original source code'? You want it to be done from the odoo client. – Gopakumar N G Jun 22 '15 at 07:50
  • Ok for example I have a class named `B` which is written in a file `class_b.py`, and I have a class named `A` which is written in a file `class_a.py`. How do I make `B` to inherit `A` without editing `class_b.py` and making another file called `custom_class_b.py` instead. What do I write in `custom_class_b.py`? – William Wino Jun 22 '15 at 10:31