This question has been flagged
5 Replies
46620 Views

Hi Odoo developers,

I would like to create a view inheriting from another view to remove some elements by using xpath expressions, but I don't want to modify the original view.

The view's code:

    <record model="ir.ui.view" id="email_compose_message_wizard_form2">
<field name="name">mi_new_view</field>
<field name="model">mail.compose.message</field>
<field name="inherit_id" ref="mail.email_compose_message_wizard_form"/>
<field name="arch" type="xml">
<xpath expr="//span[contains(.,'Followers of the document and')]"
position="replace"/>
</field>
</record>

The original view is "mail.email_compose_message_wizard_form".

My view inherits from the "mail.email_compose_message_wizard_form" view, deleting one span element.
I need that my view has all the elements from the original view except one span element.

The problem is that this span element is also deleted from the original view, and I don't want to get this.

How can I achieve this without modifying the original view?.

Thanks for your help.

EDIT (THE SOLUTION):

Thanks to Pedro Manuel Baeza for your solution in the openerp-span google group (https://groups.google.com/forum/#!topic/openerp-spain/ndfXfeFihjA)

The solution is to add 

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

in the inheriting view:

    <record model="ir.ui.view" id="email_compose_message_wizard_form2">
<field name="name">mi_new_view</field>
<field name="model">mail.compose.message</field>
<field name="inherit_id" ref="mail.email_compose_message_wizard_form"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//span[contains(.,'Followers of the document and')]"
position="replace"/>
</field>
</record>

Avatar
Discard
Best Answer

Hi,

For this you just need to inherit the original view and set the mode as primary , which will be a working as a new view from the inherited view, along with the changes applied here.

Sample:

<record id="ir_cron_view_form" model="ir.ui.view">
<field name="name">ir.cron.view.form</field>
<field name="model">ir.cron</field>
<field name="mode">primary</field>
<field name="inherit_id" ref="base.view_server_action_form"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='create_action']" position="replace">
<button name="method_direct_trigger" type="object" string="Run Manually" class="oe_highlight" attrs="{'invisible': [('state', '!=', 'code')]}"/>
</xpath>
</field>
</record>

Reference:

  1. How To Inherit And Create New Report In Odoo

  2. Apply Changes In A View For Particular User Groups In Odoo

  3. How To Inherit Views

Thanks

Avatar
Discard
Best Answer

For those non-developers out there, this is the way I solve this in Odoo online v15 without XML or dev skills:

Let's say I have a view A (standard Odoo view), and I want to create a new view B building on top of A.

To achieve the desired outcome where View B is modified based on View A without altering View A, you should select "Base View" in the "View Inheritance Mode" when using the Odoo configuration menu to duplicate the view.

Here's the correct process:

  1. Go to "Settings" in the main menu of Odoo.

  2. Under the "Technical" section, click on "Views" to access the view configuration.

  3. Locate View A in the list of views and click on it to open the view configuration form.

  4. In the form, click on the "Duplicate" button (or a similar option) to create a duplicate of View A.

  5. Modify the necessary details of the duplicated view, such as the name and any other attributes specific to View B.

  6. In the "View Inheritance Mode" field, select "Base View" from the dropdown menu.

By selecting "Base View" as the view inheritance mode, you indicate that View B is based on View A and any modifications made to View B will not alter View A.

  1. Save the changes.

Following these steps, you have created View B based on View A using the duplication feature in the Odoo configuration menu. The "Base View" inheritance mode ensures that any modifications made to View B will not affect View A.


Avatar
Discard
Best Answer

Hi,

To achieve your goal that inherit one view and do not want to change in base view then you have to define new view of the same object without inherit any other view. If you have perform inheritance then base view will always be changed.

So, just make your own new view and set it inside your menu/action. thats it.


Avatar
Discard
Author

Thanks for your answer, but what I want is not to have the same code of the view repeated two times: in the base view and the inheriting view. I only want to delete one element from the base view in my inheriting view without repeating the same xml code. It is the 'don't repeat yourself' principle. But I'm not sure whether this is possible in Odoo.

Best Answer

In Odoo/OpenERP we can inherit or use existing modules object/class/model and views. We can also inherit single field of existing modules. The question is why we need such inheritance.

The purpose of inheritance or why we need inheritance is given below:

  1. To change attributes of some fields which exists on existing/custom model (e.g. making fields readonly,invisible)

  2. To add/modify/delete old or new fields in existing/custom model (e.g. Product, Sales, HR, Fleet Management, Attendance modules model etc)

  3. We can also add buttons in already existing/custom model (form and tree) view by using inheritance

Models.py

class groups(models.Model):
 _inherit = 'res.groups'
 # we inherited res.groups model which is Odoo/OpenERP built in model and created two fields in that model.
 field_1 = fields.Char(required=True,string="Field One")
 field_2 = fields.Boolean(default=False,string="Field Two") 

XML

    
        
            res.group.form.view.inherited
            res.groups
            
            
            
            

                
                    
                                
                
                
                    
                        

                                           
        
    
  

You can get more detail about inheritance from below link:

http://learnopenerp.blogspot.com/2018/01/inheritance-in-models-and-views.html

Avatar
Discard
Best Answer

how u solved it ?

Avatar
Discard

thanks - soulation under your question