View rows hidden when no color matches criteria

Bug #925840 reported by Ronald Portier (Therp)
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Won't Fix
Wishlist
Unassigned

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).

Related branches

Revision history for this message
Raphael Collet (OpenERP) (rco-openerp) wrote :

This is not a bug. Your specification for the attribute colors is simply not correct, trailing spaces are not allowed.
However, I agree that this is a comfort issue.

Changed in openobject-server:
status: New → Won't Fix
importance: Undecided → Wishlist
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.