This question has been flagged
2 Replies
17088 Views

how it  works? and it's usages?

Avatar
Discard
Author

just saw the above link.. thanks for ur replay.

Best Answer

That it's an interesting feature of the views inheritance that I like to call it view inheritance by prototype because it's like the model inheritance by prototype where you create a copy of a model using this syntanx:

from openerp import models

class model_class_name(models.Model)
    _name = 'model.name'
    _inherit = 'new.model.name'

    ...
    ...

Defining the view like using the mode primary is the same as the model example exposed and you will end with a new view that inherit from the inherit_id view reference. That view field is only used in conjunction with the inherit_id field. By default have the value extension that it's the most used and known use.

Let's put an example assuming that you need two views of the model res.partner with different changes in how they fields will be displayed or whatever you need, could be that you don't want to use groups or invisible in all the fields that you need to add or modify in boths of the views or their position varies

<record model="ir.ui.view" id="partner_base_view">

<field name="name">Client</field>

<field name="model">res.partner</field>

<field name="priority">1</field>

<field name="arch" type="xml">

<form string="Patient">

<sheet>

<field name="image" widget='image' class="oe_left oe_avatar" options='{"preview_image": "image_medium", "size": [90, 90]}'/>

<div class="oe_left">

<label class="oe_edit_only" for="name" string="Name" colspan="4"/>

<div class="oe_inline">

<h2>

<field name="title" domain="[('domain', '=', 'contact')]" options='{"no_open": True}' placeholder="Title" nolabel="1" colspan="1"/>

<field name="name" default_focus="1" placeholder="Name" nolabel="1" colspan="5"/>

<field name="lastname" placeholder="Last Name" required="1" nolabel="1" colspan="6"/>

</h2>

</div>

<field name="category_id" widget="many2many_tags" placeholder="Tags..." colspan="6"/>

</div>

<div class="oe_right oe_button_box solt_oe_button_box" name="buttons">

<button class="oe_inline oe_stat_button" style="width: 250px !important;" type="action" name="322" icon="fa-phone" context="{'search_default_partner_id': partner_id, 'default_duration': 1.0}">

<field string="Calls" name="phonecall_count" widget="statinfo"/>

</button>

</div>

<div class="oe_clear"/>

<notebook>

<page string="Personal Information">

<group>

<field name="marital_status"/>

<field name="religion"/>

<field name="ethnic_group"/>

</group>

<label for="comments"/>

<field name="comments" placeholder="Comments"/>

</page>

</notebook>

</sheet>

<div name="message" class="oe_chatter">

<field name="message_follower_ids" widget="mail_followers" />

<field name="message_ids" widget="mail_thread" />

</div>

</form>

</field>

</record>

<record model="ir.ui.view" id="partner_primary_mode_view">

<field name="name">Client Extended</field>

<field name="model">res.partner</field>

<field name="priority">8</field>

<field name="inherit_id" ref="partner_base_view"/>

<field name="mode">primary</field>

<field name="arch" type="xml">

<xpath expr="//form/sheet/notebook" position="inside">

<page string="Extra Info">

<field name="extra_info"/>

</page>

</xpath>

</field>

</record>


Avatar
Discard
Author

thank for ur reply Axel.. :)

Author

Actually, you put model name= res.partner in both ui views. so what is the use of it? when I run it, it actually replaces partner_base_view. and only showing Partner_primary_mode_view..

Author

i found it.. i forgot XPATH, same model inheritance. but tell me in which it will be useful for us.

it's useful to create a view based on another one for the same model without having to duplicate all the view code base or changing the original one by adding invisible conditions or groups to let the original view display without modifications, you will be creating another view, not changing the original one. It's just a feature, you need to find your own scenario to use it

For example here is an example scenario that could be solved using this feature

https://www.odoo.com/es_ES/forum/ayuda-1/question/inherited-product-module-in-our-custom-module-104620

Author

just Saw.. thanks for your reply

Best Answer

but can we inherit the record that has set to primary mode and customize it

Avatar
Discard