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

Fields from 2 different models in view(inherit view and add fields from another model)?

By
Stefan Reisich
on 4/23/13, 2:52 PM 5,619 views

Hello,

my goal is to add a new model that holds new data for some categories. Not all categories needs this data. So I think inherit is not the right way, becouse if I use inheritance, every time I create a new category it will create a new row in my osc_product_category table with empty data. I want that a new row is created only when e.g. osc_category_id is set.

I want that all the new fields are shown in the product categories form. But it's not working.

class osc_product_category(osv.osv):
    _name = 'osc.product.category'
    _description = "osCommerce Product Category"

    _columns = {
        'product_category_id': fields.many2one('product.category', 'Product Category', ondelete="cascade", select=True),
        'osc_category_id': fields.integer('osCommerce Category Id'),
        ...
    }

osc_product_category()

.

<record id="nfx_oscommerce_product_category_form_view" model="ir.ui.view">
    <field name="name">nfx_oscommerce.product.category.form</field>
    <field name="model">osc.product.category</field>
    <field name="inherit_id" ref="product.product_category_form_view"/>
    <field name="arch" type="xml">

        <xpath expr="//form/sheet" position="inside">
            <notebook>
                <page string="osCommerce">
                    <group>
                        <group>
                            <field name="osc_category_id"/>
                            ...
                        </group>
                    </group>
                </page>
            </notebook>
        </xpath>

    </field>
</record>

I get an exception that parent_id was not found... I don't understand why. parent_id is in product.category. I don't need it in my osc.product.category.

How can I inherit a view and add fields from another model?

0
Sandro Regis
On 9/3/16, 2:32 PM

Hello, even you no longer using version 6, 7 or 8 you can solve the issue doing something like that:

class osc_product_category(osv.osv):_name = 'osc.product.category' _inherit = 'product.category' _description = "osCommerce Product Category" _columns = { 'product_category_id': fields.many2one('product.category', 'Product Category', ondelete="cascade", select=True), 'osc_category_id': fields.integer('osCommerce Category Id'), ... } osc_product_category(

I suggest for those that use this solution, to take a look on entity structure that was created once you run your init or update module, because as  you will see all attributes from inherit model will be created in your new model/entity.

May this could not be a good solution.

0
Marvin Taboada
On 7/19/14, 4:00 AM

Hello Stefan,

You're trying to inherit from a view that is defined for a different object (product.category), this won't work because view inheritance exists to complement object inheritance and works with the same object type:

  • https://doc.odoo.com/trunk/server/03_module_dev_03/#inheritance-in-views

You can verify this by looking at the source code, view inheritance processing retrieves views of the same model (object type):

  • https://github.com/odoo/odoo/blob/7.0/openerp/addons/base/ir/ir_ui_view.py#L169

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: 4/23/13, 2:52 PM
Seen: 5619 times
Last updated: 9/3/16, 2:32 PM