stock.location name_get results in 6.1 always ordered on id instead of on parent_left (value of _order)

Bug #1038456 reported by Jeroen Vet
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Confirmed
Low
OpenERP R&D Addons Team 2

Bug Description

There is a regression in the stock module of 6.1 (addons revno 6947). The name_get logic of the model stock.location in the has changed as compared to 6.0 but now always returns the names in order of the id of the stock location. This is because the the _complete_name method (used in name_get) returns a dictionary and a dictionary is unordered, but Python will put it in the order of the key (the id).

The problem becomes apparent when you create a view on an object that is linked to stock location (like stock.inventory) with a field with the selection widget on the stock location_id like so:

<field name="location_id" widget="selection" />

The list of values to choose from proffered by the system will be in the order of the id of the stock location instead of the expected order on the value of parent_left (this is the order specified with the _order attribute on stock.location).

Changing the original code:

    def name_get(self, cr, uid, ids, context=None):
        # always return the full hierarchical name
        res = self._complete_name(cr, uid, ids, 'complete_name', None, context=context)
        return res.items()

    def _complete_name(self, cr, uid, ids, name, args, context=None):
        """ Forms complete name of location from parent location to child location.
        @return: Dictionary of values
        """
        res = {}
        for m in self.browse(cr, uid, ids, context=context):
            names = [m.name]
            parent = m.location_id
            while parent:
                names.append(parent.name)
                parent = parent.location_id
            res[m.id] = ' / '.join(reversed(names))
        return res

by

    def name_get(self, cr, uid, ids, context=None):
        # always return the full hierarchical name
        res = self._complete_name(cr, uid, ids, 'complete_name', None, context=context)
        return res

    def _complete_name(self, cr, uid, ids, name, args, context=None):
        """ Forms complete name of location from parent location to child location.
        @return: Dictionary of values
        """
        res = []
        for m in self.browse(cr, uid, ids, context=context):
            names = [m.name]
            parent = m.location_id
            while parent:
                names.append(parent.name)
                parent = parent.location_id
            res.append((m.id, ' / '.join(reversed(names))))
        return res

solves the problem.

Changed in openobject-addons:
assignee: nobody → OpenERP R&D Addons Team 2 (openerp-dev-addons2)
importance: Undecided → Low
status: New → Confirmed
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.