← Back to team overview

openerp-india team mailing list archive

[Bug 925840] Re: View rows hidden when no color matches criteria

 

** Branch linked: lp:~therp-nl/openobject-
server/ronald@therp.nl_fix_ir_ui_view_lp925840-6.1

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

Title:
  View rows hidden when no color matches criteria

Status in OpenERP Server:
  New

Bug description:
  We have made a view definition to color rows dependant on the value in
  one of the model fields. When none of the colors is selected in any
  row, none of the rows in the view will be shown at all.

  This occurs in both the web client, as in the gtk client.

  This is an example of the color definition in the view xml:

  <attribute name="colors">grey:(active==False);blue:partner_color=='blue';forestgreen:partner_color=='green';purple:partner_color=='purple';red:partner_color=='red';orange:partner_color=='yellow';
  </attribute>

  The problem occurs when there is any row where partner_color is false,
  therefore none of the criteria applies.

  The reason is that he closing tag </attribute> is on a new line (which
  should be perfectly valid).

  A work around is to test for the value False for partner_color as well. Like this:
  <attribute name="colors">grey:(active==False);black:(partner_color==False);blue:partner_color=='blue';forestgreen:partner_color=='green';purple:partner_color=='purple';red:partner_color=='red';orange:partner_color=='yellow';
  </attribute>

  This is the code where the gtk client chokes (in bin/widget/view/tree_gtk/parser.py):
          for color_spec in attrs.get('colors', '').split(';'):
              if color_spec:
                   colour, test = color_spec.split(':')
                   treeview.colors.setdefault(colour,[])
  When no color is selected, at a certain moment color_spec will contain a lot of whitespace (a new line followed by spaces). The split method will result in an exception and the list rows, that were hidden before retrieving the data will remain hidden.

  The problem can be solved by modifying the fields_view_get method in
  orm.py to strip unwanted whitespace.

  Like this:

          # if a view was found
          if sql_res:
              source = etree.fromstring(encode(sql_res['arch']))
              # Start modification to clear unwanted whitespace.
              # (Or should this be done when loading the data in the first place...??)
              # Actually: why not resolve the whole resulting view when 
              # installing modules, instead of runtime????
              source = apply_view_inheritance(cr, user, source, sql_res['id'])
              for element in source.iter('*'):
                  # Strip white space from element:
                  if  element.text is not None and not element.text.strip():
                      element.text = None
                  # Strip whitespace from attributes:
                  for atr_key, atr_value in element.attrib.items():
                      if  atr_key and atr_value:
                          element.set(atr_key, atr_value.strip())
              # End modification to clear unwanted whitespace.
              result.update(
                  arch=source,
                  type=sql_res['type'],
                  view_id=sql_res['id'],
                  name=sql_res['name'],
                  field_parent=sql_res['field_parent'] or False)

  I will create a fix, but in the meantime will try to find out wether
  this is the most efficient solution. I guess that it might be better
  to strip of unneed and unwanted whitespace from the arch fields of
  ir_ui_view when storing the data.

  An advantage will be that with a more compact arch field, less data
  will hit the network when the view definition is send to the client
  (web or gtk).

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


References