This question has been flagged
1 Reply
5932 Views

Hai Friends ,

  I am new for OpenERP , I have doubt regards _inherits delegation in OpnenERP .

Can anyone explain _inherits delegation with examples .

Thanks & Regards OMPRAKASH.A

Avatar
Discard
Best Answer

Hi. The inherit methode has a lot of documentation around the net.: You can inherit: - xml for the views, and actions, wizzards, workflows - python codes for the deeper functionality, tables...etc

You can't inherit: - reports The first question is what do you want?

[Edited]

  1. Check the module what you want to inherit, thisi is you find out under addons dir.
  2. You must create a new module, according the followings:
    • create a folder same name what is your new module name.
    • put an __init__.py
    • put an __openerp__.py
    • put mymodule.py
    • put myview.xml inside the folder. All of that should be empty.

Put the following codes inside the __init__.py

import mymodule

this is a relation between the module and your main python code

Put the followings codes into the __openerp__.py

{
    "name" : "mymodule", # the name of the module
    "version" : "0.2", # the version of the module
    "author" : "your name", # your name :-)
    "website" : "", 
    "category" : "Generic Modules/Others", 
    "depends" : ["base","product"], #important points, as you see here must write the name of the inheritted modul name in our example product
    "description" : "your module description", 
    "init_xml" : ["myview.xml"], # important point your xml file what is definie the modified view points.
    "demo_xml" : [], 
    "update_xml" : [], #
    "active": False,
    "installable": True
}

put the following codes into the mymodule.py

class product_product(osv.osv):     
    _name = 'product.product'  # name of the inherited object, in sql you can find the table what name is product_product
    _inherit = 'product.product'
    _columns = { 
    'inheritted_recordname' : fields.char('shape',size=40, required = False, help='Some text what you want see...'),        # the inherited object column properties >> this meaning you create a new column in product_product table, what is char...and so on 
            }
product_product() # end of object def.

put the following code into the myview.xml

<record model="ir.ui.view" id="product_new_form_view_inherit"> 
    <field name="name">product.form.inherit</field>
    <field name="type">form</field>
    <field name="model">product.product</field>
    <field name="inherit_id" ref="product.product_normal_form_view"/>
    <field name="arch" type="xml">
            <field name="name" position="after">                    
    <field name="inheritted_recordname"/>                    

    </field>
    </record>

about view inherit you can find out the docs at: http://doc.openerp.com/v6.0/developer/2_6_views_events/views/view_inheritence.html

  1. Save all.
  2. Refresh the module list
  3. Install your new module.

In this case, if everithing as well, you have a new record in product object. Please watching and understanding the code.

[EDITED 2]

class test(osv.osv): 
_name = "test" 
_inherits = {"notebook.notebook" : "notebook_id" , 
"bpc.bpc" : "bpc_id"} 
_table = "test" 
_description = "Simple bpc" 
_columns = { 
'test' : fields.text('test'), 
'notebook_id' : fields.test('notebook_id'),
'bpc_id' : fields.test('bpc_id'), }

test()

In this case is usable if you want to inherit the data table values. If just the structure, may be you have a clear situation, if you make it all, one by one... "This inheritance mechanism is usually called ” instance inheritance ” or ” value inheritance ”. A resource (instance) has the VALUES of its parents."

Avatar
Discard
Author

Hi Klacus , Thanks for your reply . Actually i have question regards ( _inherits delegation ) OpenERP 1. It is possible for multiple inheritance in OpenERP , If it is possible can you please explain it with sample code . ? 2. Right now i building custom module and exploring the inheritance features in OpenERP (_inherit & _inherits delegation ) I have idea about _inherit but i have no idea about _inherits delegation . Can you please explain friend . And once again thank you klacus for your reply .

Hi. Ok. We are a bit closer. :-) Please post out your code, and we can see what we can do. You can write down what is your target, and may be I can explain to you how it's work. Please newer forget you need a lot of trial before your code will be good enough for the general use. I waiting for your codes. Regards.

Author

Hi klacus , Thanks for your reply . I will just share with you what is my need & please clear my doubt . Basically i am java developer , For my client i need to move for python (OpenERP ) . I started learning OpenERP and i realized the excellent features . Actually my role will be for my client (To create a new custom module & customize the existing module ) . After i learn OpenERP technical document & i tried to implement . Klacus still i have no idea about _inherits delegation . http://doc.openerp.com/trunk/developers/server/03_module_dev_02/#inheritance-by-delegation-inherits

Author

I used this link for my technical training . This is my sample code.... from osv import fields, osv import time

class test(osv.osv): _name = "test" _inherits = {"notebook.notebook" : "notebook_id" , "bpc.bpc" : "bpc_id"} _table = "test" _description = "Simple bpc" _columns = { 'test' : fields.text('test'), 'notebook_id' : fields.test('notebook_id'), 'bpc_id' : fields.test('bpc_id'), }

test()

Ok. I post you some basic features... :-)

Author

klacus , whether the sample code for _inherits is correct or not .. please clarify my doubt . And once again thanks for your reply

If you have a problem/ question, just put here. If I can I will help you.

Author

Hi Klacus , Thanks for your immediate reply . I can understand the point what you shared with me . Further i have doubt in Topics (Inheritance by Delegation - _inherits Syntax ::

class tiny_object(osv.osv) _name = 'tiny.object' _table = 'tiny_object' _inherits = { 'tiny.object_a': 'object_a_id', 'tiny.object_b': 'object_b_id', ... , 'tiny.object_n': 'object_n_id' } (...) Which was in the link http://doc.openerp.com/trunk/developers/server/03_module_dev_02/#inheritance-by-delegation-inherits

Yeah, the "delegation" key is a bit..... :-) So in the upside sample you can see all of the things what is there.: http://doc.openerp.com/trunk/developers/server/03_module_dev_02/#inheritance-by-delegation-inherits If you think, you question is answered please close the topic... Bye.

Author

Hi klacus , thanks for reply . I will make use of it .