Reputation: 2129
Good morning all, I would like to inherit some view from ODOO views. so that i can use it my own module. can anybody please explain me , what are the possible ways to it?
Thanks in advance.!
Upvotes: 4
Views: 7293
Reputation: 342
Here how I inherit and use the existing view for in my new module. I wanted to inherit the purchase view so in my module I inherit the purchase.order object
class purchase_order(osv.osv):
_inherit="purchase.order"
//you can add whatever fields you want here as usual
and I inherit the view like this below
<record id="purchase_order_advance_invoice_inherit_form" model="ir.ui.view">
<field name="name">purchase.order.advance.invoice.inherit.form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" **ref="purchase.purchase_order_form"**/>
//this is where I refer the view I am going to inherit, You can finish the rest tag
Upvotes: 1
Reputation: 679
View inheritance
Instead of modifying existing views in place (by overwriting them), Odoo provides view inheritance where children "extension" views are applied on top of root views, and can add or remove content from their parent.
An extension view references its parent using the inherit_id field, and instead of a single view its arch field is composed of any number of xpath elements selecting and altering the content of their parent view:
<!-- improved idea categories list -->
<record id="idea_category_list2" model="ir.ui.view">
<field name="name">id.category.list2</field>
<field name="model">idea.category</field>
<field name="inherit_id" ref="id_category_list"/>
<field name="arch" type="xml">
<!-- find field description and add the field
idea_ids after it -->
<xpath expr="//field[@name='description']" position="after">
<field name="idea_ids" string="Number of ideas"/>
</xpath>
</field>
</record>
expr An XPath expression selecting a single element in the parent view. Raises an error if it matches no element or more than one position
Operation to apply to the matched element:
inside
appends xpath's body at the end of the matched element
replace
replaces the matched element by the xpath's body
before
inserts the xpath's body as a sibling before the matched element
after
inserts the xpaths's body as a sibling after the matched element
attributes
alters the attributes of the matched element using special attribute elements in the xpath's body
Tip
When matching a single element, the position attribute can be set directly on the element to be found. Both inheritances below will give the same result.
<xpath expr="//field[@name='description']" position="after">
<field name="idea_ids" />
</xpath>
<field name="description" position="after">
<field name="idea_ids" />
</field>
Hope this help.
Upvotes: 9