Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

views inheritance for modules using _inherits tag

By
Mandeep
on 10/15/14, 7:32 AM 485 views

I am a newbie trying to create a product book by inheriting from product object. I have modelled the class as follows

class book( osv.osv):

    _name = 'book'
    _inherits = {'product.product': 'name_template'}
    _columns = {
        'isbn': fields.char('ISBN', size=50),
    }

Now when i try to inherit a view for this object from the normal product form by doing something like this

      <record model="ir.ui.view" id="view_book_form">
            <field name="name">test.books.view</field>
            <field name="model">book</field>
            <field name="inherit_id" ref="product.product_normal_form_view"/>
            <field name="arch" type="xml">
                 <field name="name" position="after">
                        <field name="isbn"/>
                 </field>
            </field>
        </record>

I get errors saying that onchange event is not there in the new class. How should i achieve this? If i alternately try to use the _inherit tag, things seem to be working fine. 

 

1
Piyush Suva
On 10/15/14, 7:44 AM

Use This Below Way....

class book( osv.osv):

    _name = 'book'
    _inherits = {'product.product':'product_id'}
    _columns = {
        'isbn': fields.char('ISBN', size=50),

        'product_id':fields.many2one('product.product', Product, ondelete="cascade")
    }

 

<record model="ir.ui.view" id="view_book_form">
            <field name="name">test.books.view</field>
            <field name="model">book</field>
              <field name="arch" type="xml">

                  <form string="Course Registration" version="7.0">
                        <field name="isbn"/>
                        <!-- And All other needed product's fields you can define here directly , see example name, type etc.. -->

                        <field name="name"/> 

                       <field name="type"/>
                 </field>
            </field>
        </record>

 

Thanks for your reply. But this is not equivalent to inheriting the views. I just want to add the new fields in the inherited view

Mandeep
on 10/15/14, 8:30 AM

Bro. then just take class product_product(osv.osv): _inherit = 'product.product' _columns={ #Add ur field }

Piyush Suva
on 10/15/14, 8:37 AM

Ok Thanks. I was not doing that thinking about the impact it would have on interaction with other modules like accounts, Inventory etc.since this would create new tables. Would they behave similarly?

Mandeep
on 10/15/14, 9:01 AM

dont warry bro , it will not create new table , if your code like above 'Comment' using _inherit = 'product.product' then it will just add new field in product_product table of your database, if you give attribute _table_name then only it will create new table of given name. you can test it.

Piyush Suva
on 10/15/14, 9:21 AM
0

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 10/15/14, 7:42 AM

There are two type of Inheritence :

1. Object Inheritance - _inherit

2. Inheritance by Delegation - _inherits

So am guessing you want to inherit fields from Product Object and derive your custom module  "book" object .. If that is the case, do use "inherit"

Your code goes like this:

class book( osv.osv):

    _name = 'book'
    _inherit = 'product.product'

...

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/15/14, 7:32 AM
Seen: 485 times
Last updated: 3/16/15, 8:10 AM