View inheritance positioning

Asked by hsm flxCore

I'm trying to add a column (field) to heavy nested tree.

I need to position (after, before, inside, replace) the field, but I am not able to this.

I get various errors in different cases:

When trying
<field name="x" position="after" />
<field name="new_field"/>

I get the error that 'x' is a duplicate.

The other error tells me that XML is incorrect (while it isn't).
How is this posisble?

I will show what I want to get accomplished. First the View Architecture as is and then the View Architecture as needed. I'm concerned about a 'fdate' field. (<field name="fdate"/>)

<?xml version="1.0"?>

                <form string="Timesheet">
                    <field name="name"/>
                    <field name="user_id"/>
                    <field name="date_from"/>
                    <field name="date_to"/>

                    <notebook colspan="4">
                        <page string="Daily View">
                            <group col="6" colspan="4">
                                <button name="button_dummy" string="Go to:" type="object"/>
                                <field name="date_current" nolabel="1"/>
                                <label string=""/>
                                <button icon="gtk-media-previous" name="date_previous" string="" type="object"/>
                                <button name="date_today" string="Today" type="object"/>
                                <button icon="gtk-media-next" name="date_next" string="" type="object"/>
                            </group>

                            <field colspan="3" context="name=date_current,user_id=user_id" groups="hr_attendance.group_hr_attendance" height="100" name="attendances_ids" nolabel="1">
                                <tree string="Attendances">
                                    <field name="name"/>
                                    <field name="action"/>
                                    <field invisible="1" name="employee_id"/>
                                </tree>
                            </field>
                            <group col="1" colspan="1" groups="hr_attendance.group_hr_attendance">
                                <button name="sign_in" string="Sign In" type="object"/>
                                <button name="sign_out" string="Sign Out" type="object"/>
                            </group>

                            <field groups="hr_attendance.group_hr_attendance" name="state_attendance"/>
                            <field groups="hr_attendance.group_hr_attendance" name="total_attendance_day" widget="float_time"/>
                            <field colspan="4" context="date=date_current,user_id=user_id" domain="[('name','=',date_current)]" name="timesheet_ids" nolabel="1">
                                <tree editable="top" string="Timesheet">
                                    <field invisible="1" name="date"/>
                                    <field domain="[('type','=','normal'), ('state', '&lt;&gt;', 'close')]" name="account_id" on_change="on_change_account_id(account_id)"/>
                                    <field name="name"/>
                                    <field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)" widget="float_time"/>
                                    <field name="to_invoice"/>
                                    <field invisible="1" name="journal_id"/>
                                    <field invisible="1" name="product_id"/>
                                    <field invisible="1" name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)"/>
                                    <field name="amount"/>
                                    <field name="general_account_id"/>
                                    <field invisible="1" name="user_id" required="1"/>
                                </tree>
                                <form string="Timesheet">
                                    <field name="date"/>
                                    <field domain="[('type','=','normal'), ('state', '&lt;&gt;', 'close')]" name="account_id" on_change="on_change_account_id(account_id)"/>
                                    <field name="name"/>
                                    <field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)" widget="float_time"/>
                                    <field name="to_invoice"/>
                                    <field invisible="1" name="journal_id"/>
                                    <field invisible="1" name="product_id"/>
                                    <field invisible="1" name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)"/>
                                    <field name="amount"/>
                                    <field name="general_account_id"/>
                                    <field name="user_id" required="1"/>
                                </form>
                            </field>
                            <field name="total_difference_day" widget="float_time"/>
                            <field name="total_timesheet_day" widget="float_time"/>
                        </page>
                        <page string="By Day">
                            <field colspan="4" name="period_ids" nolabel="1">
                                <tree colors="red:total_difference&lt;=0.1;blue:total_difference&gt;=0.1" string="Period">
                                    <field name="name"/>
                                    <field groups="hr_attendance.group_hr_attendance" name="total_attendance" widget="float_time"/>
                                    <field name="total_timesheet" widget="float_time"/>
                                    <field groups="hr_attendance.group_hr_attendance" name="total_difference" widget="float_time"/>
                                </tree>
                            </field>
                            <field name="total_attendance" widget="float_time"/>
                            <field name="total_timesheet" widget="float_time"/>
                            <field name="total_difference" widget="float_time"/>
                        </page>
                    </notebook>
                    <field name="state"/>
                    <group col="4" colspan="2">
                        <button name="button_confirm" states="draft" string="Confirm" type="object"/>
                        <button name="action_set_to_draft" states="done" string="Set to Draft" type="object"/>
                        <button name="cancel" states="confirm" string="Refuse"/>
                        <button name="done" states="confirm" string="Accept"/>
                    </group>
                </form>

============needed:

<?xml version="1.0"?>

                <form string="Timesheet">
                    <field name="name"/>
                    <field name="user_id"/>
                    <field name="date_from"/>
                    <field name="date_to"/>

                    <notebook colspan="4">
                        <page string="Daily View">
                            <group col="6" colspan="4">
                                <button name="button_dummy" string="Go to:" type="object"/>
                                <field name="date_current" nolabel="1"/>
                                <label string=""/>
                                <button icon="gtk-media-previous" name="date_previous" string="" type="object"/>
                                <button name="date_today" string="Today" type="object"/>
                                <button icon="gtk-media-next" name="date_next" string="" type="object"/>
                            </group>

                            <field colspan="3" context="name=date_current,user_id=user_id" groups="hr_attendance.group_hr_attendance" height="100" name="attendances_ids" nolabel="1">
                                <tree string="Attendances">
                                    <field name="name"/>
                                    <field name="action"/>
                                    <field invisible="1" name="employee_id"/>
                                </tree>
                            </field>
                            <group col="1" colspan="1" groups="hr_attendance.group_hr_attendance">
                                <button name="sign_in" string="Sign In" type="object"/>
                                <button name="sign_out" string="Sign Out" type="object"/>
                            </group>

                            <field groups="hr_attendance.group_hr_attendance" name="state_attendance"/>
                            <field groups="hr_attendance.group_hr_attendance" name="total_attendance_day" widget="float_time"/>
                            <field colspan="4" context="date=date_current,user_id=user_id" domain="[('name','=',date_current)]" name="timesheet_ids" nolabel="1">
                                <tree editable="top" string="Timesheet">
                                    <field invisible="1" name="date"/>
                                    <field domain="[('type','=','normal'), ('state', '&lt;&gt;', 'close')]" name="account_id" on_change="on_change_account_id(account_id)"/>
                                    <field name="name"/>
                                    <field name="fdate"/>
                                    <field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)" widget="float_time"/>
                                    <field name="to_invoice"/>
                                    <field invisible="1" name="journal_id"/>
                                    <field invisible="1" name="product_id"/>
                                    <field invisible="1" name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)"/>
                                    <field name="amount"/>
                                    <field name="general_account_id"/>
                                    <field invisible="1" name="user_id" required="1"/>
                                </tree>
                                <form string="Timesheet">
                                    <field name="date"/>
                                    <field domain="[('type','=','normal'), ('state', '&lt;&gt;', 'close')]" name="account_id" on_change="on_change_account_id(account_id)"/>
                                    <field name="name"/>
                                    <field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)" widget="float_time"/>
                                    <field name="to_invoice"/>
                                    <field invisible="1" name="journal_id"/>
                                    <field invisible="1" name="product_id"/>
                                    <field invisible="1" name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)"/>
                                    <field name="amount"/>
                                    <field name="general_account_id"/>
                                    <field name="user_id" required="1"/>
                                </form>
                            </field>
                            <field name="total_difference_day" widget="float_time"/>
                            <field name="total_timesheet_day" widget="float_time"/>
                        </page>
                        <page string="By Day">
                            <field colspan="4" name="period_ids" nolabel="1">
                                <tree colors="red:total_difference&lt;=0.1;blue:total_difference&gt;=0.1" string="Period">
                                    <field name="name"/>
                                    <field groups="hr_attendance.group_hr_attendance" name="total_attendance" widget="float_time"/>
                                    <field name="total_timesheet" widget="float_time"/>
                                    <field groups="hr_attendance.group_hr_attendance" name="total_difference" widget="float_time"/>
                                </tree>
                            </field>
                            <field name="total_attendance" widget="float_time"/>
                            <field name="total_timesheet" widget="float_time"/>
                            <field name="total_difference" widget="float_time"/>
                        </page>
                    </notebook>
                    <field name="state"/>
                    <group col="4" colspan="2">
                        <button name="button_confirm" states="draft" string="Confirm" type="object"/>
                        <button name="action_set_to_draft" states="done" string="Set to Draft" type="object"/>
                        <button name="cancel" states="confirm" string="Refuse"/>
                        <button name="done" states="confirm" string="Accept"/>
                    </group>
                </form>

Question information

Language:
English Edit question
Status:
Solved
For:
OpenERP Edit question
Assignee:
No assignee Edit question
Solved by:
Vinay Rana (OpenERP)
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) said :
#1

Hello Hannes,

You need to use '<xpath>' for this kind of view changes.
The following inherited view will do your task:

  <record model="ir.ui.view" id="hr_timesheet_sheet_form_inherit_1">
   <field name="name">hr.timesheet.sheet.form</field>
   <field name="model">hr_timesheet_sheet.sheet</field>
   <field name="inherit_id" ref="hr_timesheet_sheet.hr_timesheet_sheet_form"/>
   <field name="type">form</field>
   <field name="arch" type="xml">
    <xpath expr="/form/notebook/page/field[@name='timesheet_ids']/tree/field[@name='name']" position="after">
     <field name="fdate"/>
    </xpath>
   </field>
  </record>

Hope this will help you.
Thanks.

Revision history for this message
hsm flxCore (hannes-smit) said :
#2

Thanks vra (openerp), that solved my question.

Revision history for this message
hsm flxCore (hannes-smit) said :
#3
Revision history for this message
hsm flxCore (hannes-smit) said :
#4

Is it possible to do two xpaths? for example:

 <field name="arch" type="xml">
    <xpath expr="/form/notebook/page/field[@name='timesheet_ids']/tree/field[@name='name']" position="after">
     <field name="fdate" />
    </xpath>
    <xpath expr="/form/notebook/page/field[@name='timesheet_ids']/tree/field[@name='unit_amount']" position="replace">
                   <field name="unit_amount2" />
       </xpath>
           </field>

Revision history for this message
hsm flxCore (hannes-smit) said :
#5

Please?

Revision history for this message
Best Vinay Rana (OpenERP) (vra-openerp) said :
#6

Hello Hannes,

You need to create another view for this with different id in following way:

  <record model="ir.ui.view" id="hr_timesheet_sheet_form_inherit_2">
   <field name="name">hr.timesheet.sheet.form</field>
   <field name="model">hr_timesheet_sheet.sheet</field>
   <field name="inherit_id" ref="hr_timesheet_sheet.hr_timesheet_sheet_form"/>
   <field name="type">form</field>
   <field name="arch" type="xml">
    <xpath expr="/form/notebook/page/field[@name='timesheet_ids']/tree/field[@name='unit_amount']" position="replace">
                   <field name="unit_amount2" />
       </xpath>
   </field>
  </record>

Thanks.

Revision history for this message
hsm flxCore (hannes-smit) said :
#7

Thanks vra (openerp), that solved my question.

Revision history for this message
Don Kirkby (donkirkby) said :
#8

To modify two different sections of a view, you can wrap them in a <data> element. I know it works with <field> elements, but I expect it will also work with <xpath>:

    ...
    <field name="arch" type="xml">
        <data>
            <xpath expr="..." position="after">
                <field name="fdate"/>
            </xpath>
            <xpath expr="..." position="replace">
                <field name="unit_amount2"/>
            </xpath>
        </data>
    </field>

I've updated the documentation, but it may not be regenerated for a while:
http://doc.openerp.com/developer/2_6_views_events/views/view_inheritence.html

Revision history for this message
Pierre Girard (pierreg27) said :
#9

i would like to know if its possible to add that have no name after an other one of that type too?

exemple: that is the original view.

       <record id="view_res_partner_filter" model="ir.ui.view">
            <field name="name">res.partner.select</field>
            <field name="model">res.partner</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <search string="Search Partner">
                   <group col='10' colspan='4'>
                        <filter string="Customers" name="customer" icon="terp-personal" domain="[('customer','=',1)]" help="Customer Partners"/>
                        <filter string="Suppliers" name="supplier" icon="terp-personal" domain="[('supplier','=',1)]" help="Supplier Partners"/>
                        <!--<filter string="Employee" name="employee" icon="terp-personal" domain="[('employee','=',1)]" help="Employee Partners"/>-->
                        <separator orientation="vertical"/>
                        <field name="name" select="1"/>
                        <field name="address" select="1"/>
                        <field name="country" select="1"/>
                        <field name="category_id" select="1" groups="base.group_extended"/>
                        <field name="user_id" select="1">
                            <filter string="My Partners" icon="terp-personal+" domain="[('user_id','=',uid)]"/>
                        </field>
                   </group>
                   <newline />
                   <group expand="0" string="Group By...">
                       <filter string="Salesman" icon="terp-personal" domain="[]" context="{'group_by' : 'user_id'}" />
                   </group>
               </search>
            </field>
        </record>

I have to put a group by for categories after the one for user id, but i don't have the name for the one of the user id.
I am not sure of how to make the xpath thing in this situation, if someone could give me and example that would be great!

Revision history for this message
Don Kirkby (donkirkby) said :
#10

I think you can use any attributes to specify the element to insert after, so you should be able to do something like this:

<field name="arch" type="xml">
    <filter string="Salesman" position="after">
        ... whatever you want to add
    </filter>
</field>