Ir al contenido
Menú
Se marcó esta pregunta
14 Respuestas
48953 Vistas

Hi,

My question is how to add new tab or (tabs) in my module or existing module

I know the we need to inherit the module we want to add some things and do our changes (As what I do previously (adding one2may & many2one fields))

see below picture will explain what I need

image description

Thank you in advance

Avatar
Descartar
Mejor respuesta

To add page in employee after personal information tab you need to inherit the employee form view in xml like,

 <record id="view_employee_form" model="ir.ui.view">
   	<field name="name">hr.employee.form</field>
    <field name="model">hr.employee</field>
    <field name="inherit_id" ref="view_employee_form"/>
    <field name="arch" type="xml">
	    <xpath expr="//page[@string='Personal Information']" position='after'>
	    	<page string='My new tab'>
	    		
	    	</page>
	    </xpath>
    </field>
</record>
Avatar
Descartar

It didn't work for me initially in Odoo 13. I needed to edit this: expr="//page[@string='Personal Information']"

After changing @string to @name and then changing "Personal Information" to the proper name value of the page, it worked. Thanks Atul!

@Bienvenido Villabroza, yes you are correct, @sting is not working on the newer version. my above answer will perfectly in v8 or lower version

what should i do if i want to show this tab only for the sales department

Mejor respuesta

In form view, inside <notebook> tag you can add as many pages(TAB) by this syntax

 <notebook>
     <page string="Your Tab1">
         <field name="..."/>
     </page>  
     <page string="Your Tab2">
         <field name="..."/>
     </page>   
 </notebook>
Avatar
Descartar
Mejor respuesta

hello Math

Here for you I'm adding new tab in "Quotations" of "sale" module,this is similar to your requirement

Example.py

from openerp import fields, models, api, _

class class_name(models.Model):

    _inherit = 'sale.order'
    <fields name="..."/>

Example.xml

<record id="view_sale_order_tree" model="ir.ui.view">
<field name="name">view.sale.order.tree</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">

<xpath expr="//page[@string='Other Information']" position="after">
<page string="My_New_Tab">
<field name='My_new_fields'/>
</page>
   </xpath>

</field>
</record>


Avatar
Descartar
Mejor respuesta

inside <notebook> tag, after <page string="Personal Information"> </page> put your new tab, <page string="My Tab"> </page>

Avatar
Descartar
Mejor respuesta

You need to add a new page in the notebook in the View. Are you creating an own Addon/Module to alter the partner page?

In case of you do please take a look on that: You need to inherit from the partner view in maybe partner_view.xml:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
    <!--
    Partners Extension
  -->

    <record id="view_partner_property_form" model="ir.ui.view">
        <field name="name">res.partner.stock.property.form.inherit</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="product.view_partner_property_form"/>
        <field name="arch" type="xml">
            <notebook position="inside">
                <page string="My New Tab">
                    <field name="..."/>
                </page>
            </notebook>
        </field>
    </record>

  </data>
</openerp>
Avatar
Descartar
Autor

What I do without inherit view (inherit the module) <!-- ============== student================= --> <!-- 1st part of the sim_view start--> <record model="ir.ui.view" id="student_form"> <field name="name">Student</field> <field name="model">sim77.student</field> <field name="type">form</field> <field name="arch" type="xml"> <form string="Student"> <field name="name"/> <field name="student_name"/>

<field name="gender"/> <field name="contract_id"/> </form> </field> </record> <!-- 1st part of the sim_view end--> can you help ? where I put code of new page?

Then add a notebook to your view. That looks exactly as above code just without the "inherit_id" tag nor the position attribute in <notebook>. Notebook adds the Space for your Tabs to the form.

You put the code of the new File in a separate .xml file. Then you need to add the .xml in your __openerp__.py under "update_xml". Just take a look to other addons therefor.

Did that solved your Problem? If it does please mark one of the correct answers to help others to find the solution faster

Great, this works fine for me. I have a one2many field in the partner model that creates a relationship with custom model. How can I add a "Create" button to the tab so that it pop up the view of the custom model?

Mejor respuesta

How can we set one tab or page as default, i.e., when i open the screen that that tab opens by default

 

Avatar
Descartar

I would want to know too!

Put it the first not the last hhhh ;)

Mejor respuesta

For adding a new tab your xpath had to be like this

<xpath expr="//page[2]" position='after'>
1,2,3 depending the number of your tab in the view.
Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
may 22
2497
0
jul 24
1924
1
nov 20
4058
1
oct 20
4688
1
ene 20
4629