Move elements in view architecture instead of delete and reinsert them

Bug #1132894 reported by Daniel Hammerschmidt
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Confirmed
Wishlist
OpenERP's Framework R&D

Bug Description

Sometimes we need to move an element to another position in the view. Other installed modules may have touched them and added or changes some attributes. If we first delete the field or group or whatever and then reinsert at the new position (with copy and paste from the "original" xml definition) we may loose those modifications.

There should be a way to simply move the element to the new position and keeping its attributes and content.

      <xpath expr="//field[@name='function']" position="move" before="//label[@for='street']"/>
      <xpath expr="//field[@name='title']" position="move" after="//field[@name='function']"/>

I figured out a way with small changes to osv/orm.py/BaseModel::fields_view_get()::apply_inheritance_specs()

                     elif pos == 'attributes':
                         for child in spec.getiterator('attribute'):
                             attribute = (child.get('name'), child.text and child.text.encode('utf8') or None)
                             if attribute[1]:
                                 node.set(attribute[0], attribute[1])
                             else:
                                 del(node.attrib[attribute[0]])
+ elif pos == 'move':
+ expr2 = spec.get('before')
+ if expr2:
+ move_after = False
+ else:
+ move_after = True
+ expr2 = spec.get('after')
+ if expr2 is None:
+ raise_view_error("New position to move to is missing.", inherit_id)
+ node2 = source.xpath(expr2)
+ node2 = node2[0] if node2 else None
+ if node2 is None:
+ raise_view_error("Invalid position to move to.", inherit_id)
+ parent2 = node2.getparent()
+ node2_index = parent2.index(node2)
+ parent2.insert(node2_index + (1 if move_after else 0), node)
                     else:

Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Wishlist
status: New → Confirmed
Revision history for this message
Daniel Hammerschmidt (redneck) wrote :

I rewrote the code given above (and created a diff-file). Now supported move-targets are inside, before and after and (I think) the code looks more pythonic.

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

Other bug subscribers

Remote bug watches

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