Using position="after" in inherited view adds the fields in reverse order

Bug #455547 reported by Russell Briggs
30
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Status tracked in Trunk
5.0
Fix Released
Medium
Anup(SerpentCS)
Trunk
Fix Released
Medium
Unassigned

Bug Description

Applies to 5.0.6

For example, if I use the following 'arch' XML in an inherited view:

            <field name="arch" type="xml">
                <field name="my_field" position="after">
                    <field name="field1" />
                    <field name="field2" />
                    <field name="field3" />
                    <field name="field4" />
                </field>
            </field>

The resulting screen will display the fields in the following order:

my_field
field4
field3
field2
field1

My guess is that the server is calling the 'insert after' xml method for each sub-tag in order.

The fix will be to call the 'insert after' xml method for each of the sub-tags in reverse order, so that field1 is inserted last, so it appears directly after my_field

I will use the position="replace" method as a workaround for now.

Revision history for this message
Russell Briggs (russell-briggs) wrote :

Have just noticed this does not seem to affect listviews, so I guess it could be a Web Client problem?

Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello Russell Briggs,

   I checked by installing the account_voucher. After installing the account module. As it inherits the view of account. and adds four fields after "user_type". and the fields are coming as required and not in the reverse order. I checked in the GTK-client as well as the Web-client. It doesn't seem to be a real bug.
  IMHO it'll be better if you add <newline/> after you place many fields It'll help parser.

Thank you.

Changed in openobject-server:
status: New → Invalid
Revision history for this message
Russell Briggs (russell-briggs) wrote :

Hi Anup

Appologies - although i was using version 5.0.6 of the web client, i was using the trunk build of the server (revision 1887).

I have switched to the 5.0 stable branch of the server and can confirm that the issue does not exist. Sorry for wasting your time!

Cheers

Russ

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hi Russel,

No need to apologize at all.

You may user replace,after,before at your convenience.

Better option is to add newline when you have more than 1 fields for operations.

Thank you.

Revision history for this message
Nicolas DS (zyphos) wrote :
Download full text (3.2 KiB)

This bug is still valid, the bug appear only if the selected field is the last of its own stack !!!
:
        <record id="view_partner_category_form_partner" model="ir.ui.view">
            <field name="name">res.partner.category.form.partner</field>
            <field name="model">res.partner.category</field>
            <field name="inherit_id" ref="base.view_partner_category_form"/>
            <field name="arch" type="xml">
                <xpath expr="/form/field[@name='parent_id']" position="after">
                    <newline />
                    <separator colspan="4" string="Partners"/>
                    <field colspan="4" name="partner_ids" nolabel="1"/>
                </xpath>
            </field>
        </record>

it leads to this from a server answer to a view ask (in the DEBUG_RPC log):

<form string="Partner Category">
    <field name="name" select="1"/>
    <field name="active" select="1"/>
    <field name="parent_id"/>
    <field colspan="4" name="partner_ids" nolabel="1"/>
    <separator colspan="4" string="Partners"/>
    <newline/>
</form>

Indeed in code (server/bin/osv/orm.py @ line 1261):
                   else:
                       sib = node.getnext()
                        for child in node2:
                            if pos == 'inside':
                                node.append(child)
                            elif pos == 'after':
                                if sib is None:
                                    node.addnext(child)
                                else:
                                    sib.addprevious(child)
                            elif pos == 'before':
                                node.addprevious(child)
                            else:
                                raise AttributeError(_('Unknown position in inherited view %s !') % pos)

Our nodes are like this (DOM):
+ name
+ active
+ parent_id (the "node" var in code)

The actual code will do this:
1. <newline />
   * sib = None (the node is the last of its stack)
   * add after "node"
   * result DOM:
      + name
      + active
      + parent_id
      + newline
2. <separator colspan="4" string="Partners"/>
   * sib = "newline node"
   * add BEFORE "newline node"
   * result DOM:
      + name
      + active
      + parent_id
      + separator
      + newline
3. <field colspan="4" name="partner_ids" nolabel="1"/>
   * sib = "separator node"
   * add BEFORE "separator node"
   * result DOM:
      + name
      + active
      + parent_id
      + partner_ids
      + separator
      + newline

The patch to correct this is the following one (server/bin/osv/orm.py @ line 1261) :
                    else:
                        for child in node2:
                            if pos == 'inside':
                                node.append(child)
                            elif pos == 'after':
                                node.addnext(child)
                                node = child
                            elif pos == 'before':
                                node.addprevious(child)
                            else:
                                raise AttributeError(_('Unknown...

Read more...

Changed in openobject-server:
status: Invalid → Confirmed
Revision history for this message
Nicolas DS (zyphos) wrote :

This bug is in trunk too !

Here is the patch for the trunk version of Openobject server.

Revision history for this message
Ferdinand (office-chricar) wrote :

I confirm the bug in trunk r 2228

Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello NIcolas,

  We really appreciate your efforts. I have found an optimized solution for the problem. Here are the patches for stable and trunk both. With your patch the problem was only that if we need to add a field between two previously existing fields then it won't work. So would you please check the attached patch and give your views.

Thanks.

Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :
Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Here's the patch for stable.
Thanks.

Revision history for this message
Nicolas DS (zyphos) wrote :

Hi Anup,
with the patches I provided everything works as expected in all conditions.
Even in the case you describe (add a field between 2 previously created)
I removed in the patches the code no more usefull. (saving the next item)

It works like this:
Original nodes :
+ A
+ B
+ C
Nodes to add after B:
+D
+E

With the patches:

1. Deal with D:
node = B
child = D
node.addnext(child)
node = child = D
1. Result:
+ A
+ B
+ D
+ C

2. Deal with E:
node = D (thank's to the "node = child")
child = E
node.addnext(child)
node = child
2. Result:
+ A
+ B
+ D
+ E
+ C

As expected...

Revision history for this message
Nicolas DS (zyphos) wrote :

This bug has been duplicated and is fixed in trunk by using your patch.
https://bugs.launchpad.net/openobject-server/+bug/686275

http://bazaar.launchpad.net/~openerp/openobject-server/trunk/revision/3097
Revision ID: <email address hidden>

But some code is useless now... like I already told (the "sib" thing) the follow code is enough:
                     else:
                         for child in node2:
                             if pos == 'inside':
                                 node.append(child)
                             elif pos == 'after':
                                 node.addnext(child)
                                 node = child
                             elif pos == 'before':
                                 node.addprevious(child)
                             else:

Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) wrote :

This issue is already fixed with current trunk code.

Thanks.

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

It has been fixed in stable by revision 2166 <email address hidden> authored to Nicolas DS and Anup(OpenERP).
Thanks guys.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.