← Back to team overview

openerp-india team mailing list archive

[Bug 1038456] [NEW] stock.location name_get results in 6.1 always ordered on id instead of on parent_left (value of _order)

 

Public bug reported:

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.

** Affects: openobject-addons
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/1038456

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

Status in OpenERP Addons (modules):
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/1038456/+subscriptions


Follow ups

References