Mohammed Shekha(Open ERP) has proposed merging 
lp:~openerp-dev/openobject-client-web/6.0-opw-30826-msh into 
lp:openobject-client-web/6.0.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-client-web/6.0-opw-30826-msh/+merge/82790

Hello,

Fixed the issue of colors attrs not working in treegrid.

Demo : Apply colors attrs on any treegrid for example products by category, the 
colors will not be shown based on condition.

Reason : The colors attrs feature was not there in treegrid.

Changed the code so that colors attrs works in treegrid with condition.

Thanks. 
-- 
https://code.launchpad.net/~openerp-dev/openobject-client-web/6.0-opw-30826-msh/+merge/82790
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-client-web/6.0-opw-30826-msh.
=== modified file 'addons/openerp/controllers/tree.py'
--- addons/openerp/controllers/tree.py	2011-05-10 07:16:46 +0000
+++ addons/openerp/controllers/tree.py	2011-11-19 18:16:26 +0000
@@ -33,7 +33,7 @@
 from openobject.tools import url, expose
 
 from openerp.controllers import SecuredController
-from openerp.utils import rpc, cache, icons, common, TinyDict
+from openerp.utils import rpc, cache, icons, common, TinyDict, expr_eval
 from openerp.widgets import tree_view
 
 FORMATTERS = {
@@ -131,7 +131,7 @@
 
     @expose('json')
     def data(self, ids, model, fields, field_parent=None, icon_name=None,
-             domain=[], context={}, sort_by=None, sort_order="asc", fields_info=None):
+             domain=[], context={}, sort_by=None, sort_order="asc", fields_info=None, colors={}):
         
         if ids == 'None' or ids == '':
             ids = []
@@ -150,6 +150,9 @@
         if isinstance(context, basestring):
             context = eval(context)
         
+        if isinstance(colors, basestring):
+            colors = eval(colors)
+            
         if isinstance(fields_info, basestring):
             fields_info = simplejson.loads(fields_info)
 
@@ -173,6 +176,16 @@
             fields_info_type = simplejson.loads(fields_info[sort_by])
             result.sort(lambda a,b: self.sort_callback(a, b, sort_by, sort_order, type=fields_info_type['type']))
 
+        for item in result:
+            if colors:
+                for color, expr in colors.items():
+                    try:
+                        if expr_eval(expr,item or False):
+                            item['color'] = color
+                            break
+                    except:
+                            pass
+
         # format the data
         for field in fields:
             field_info = simplejson.loads(fields_info[field])

=== modified file 'addons/openerp/static/javascript/treegrid.js'
--- addons/openerp/static/javascript/treegrid.js	2011-01-24 09:01:47 +0000
+++ addons/openerp/static/javascript/treegrid.js	2011-11-19 18:16:26 +0000
@@ -320,7 +320,7 @@
             var key = header.name;
             var value = this.record.items[key];
 
-            var td = MochiKit.DOM.TD({'class': header.type || null, 'width' : header.width || null});
+            var td = MochiKit.DOM.TD({'class': header.type || null, 'width' : header.width || null, 'style':{'color':this.record.items['color']}});
             if (i == 0) { // first column
 
                 var row = [];
@@ -338,7 +338,7 @@
 
                 row.push(arrow);
 
-                value = MochiKit.DOM.createDOM('A', {'href': '#'}, value);
+                value = MochiKit.DOM.createDOM('A', {'href': '#','style':{'color':this.record.items['color']}}, value);
                 this.element_a = value;
 
                 this.eventOnKeyDown = MochiKit.Signal.connect(value, 'onkeydown', this, this.onKeyDown);

=== modified file 'addons/openerp/widgets/tree_view.py'
--- addons/openerp/widgets/tree_view.py	2011-01-17 11:57:11 +0000
+++ addons/openerp/widgets/tree_view.py	2011-11-19 18:16:26 +0000
@@ -69,7 +69,13 @@
 
         ids = []
         id = res_id
-
+        
+        colors = {}
+        for color_spec in attrs.get('colors', '').split(';'):
+            if color_spec:
+                colour, test = color_spec.split(':')
+                colors[colour] = test
+                
         if self.toolbar:
             ids = proxy.search(self.domain2, 0, 0, 0, ctx)
             self.toolbar = proxy.read(ids, ['name', 'icon'], ctx)
@@ -94,7 +100,8 @@
                                       context=self.context,
                                       field_parent=self.field_parent,
                                       onselection="onSelection",
-                                      fields_info=fields_info)
+                                      fields_info=fields_info,
+                                      colors=colors)
         self.id = id
         self.ids = ids
 

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to