Skip to content

Commit ee547fd

Browse files
committed
[IMP] web_tree_dynamic_colored_field: Allow to set row colors from specific fields for entire list
1 parent 5d304a7 commit ee547fd

File tree

11 files changed

+418
-192
lines changed

11 files changed

+418
-192
lines changed

web_tree_dynamic_colored_field/README.rst

Lines changed: 85 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,42 @@ Colorize field in tree views
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
3030

31-
This module aims to add support for dynamically coloring fields in tree
31+
This module aims to add support for dynamically coloring fields in list
3232
view according to data in the record.
3333

3434
Features
3535
--------
3636

3737
- Add attribute ``bg_color`` on field's ``options`` to color background
38-
of a cell in tree view
38+
of a cell in list view
3939
- Add attribute ``fg_color`` on field's ``options`` to change text color
40-
of a cell in tree view
40+
of a cell in list view
41+
- Add attribute ``bg_color_field`` on list's ``colors`` to change
42+
background color of the entire row in list view (\*)
43+
- Add attribute ``fg_color_field`` on list's ``colors`` to change text
44+
color of the entire row in list view (\*)
45+
46+
(\*) This functionality only works for a list defined in a form. (Since
47+
13.0, the ``colors`` attribute is no longer in the RelaxNG schema of the
48+
list view, so we can't use it like before, but it looks like the RNG is
49+
not checked for embedded list.)
50+
51+
Testing
52+
-------
53+
54+
Some views are overriden for demoing this module functionnalities:
55+
56+
1. On the Users list view: The ``name`` and ``login_date`` fields are
57+
colored according to conditions written in view definition.
58+
2. On the Groups form view > "Access Rights": By renaming the rule name
59+
to a color (red, blue, yellow, #00FDF0), the entire row background
60+
color is immediatly updated.
61+
3. On the System Parameters list view:
62+
63+
- For the ``key`` field: Its content is the text color, the ``value``
64+
field is its background color.
65+
- For the ``value`` field: Its content is the text color, the
66+
``value`` field is its background color.
4167

4268
**Table of contents**
4369

@@ -47,92 +73,113 @@ Features
4773
Usage
4874
=====
4975

50-
- In the tree view declaration, put
76+
Using view conditions
77+
=====================
78+
79+
- In the list view declaration, put
5180
``options='{"bg_color": "red: customer==True"}`` attribute in the
5281
``field`` tag:
5382

54-
::
83+
.. code:: xml
5584
5685
...
5786
<field name="arch" type="xml">
58-
<tree string="View name">
87+
<list string="View name">
5988
...
6089
<field name="name" options='{"bg_color": "red: customer == True"}'/>
6190
...
62-
</tree>
91+
</list>
6392
</field>
6493
...
6594
66-
With this example, column which renders 'name' field will have its **background** colored in red on customer records.
95+
With this example, column which renders 'name' field will have its
96+
**background** colored in red on customer records.
6797

68-
- In the tree view declaration, put
98+
- In the list view declaration, put
6999
``options='{"fg_color": "white:customer == True"}'`` attribute in the
70100
``field`` tag:
71101

72-
::
102+
.. code:: xml
73103
74104
...
75105
<field name="arch" type="xml">
76-
<tree string="View name">
106+
<list string="View name">
77107
...
78108
<field name="name" options='{"fg_color": "white:customer == True"}'/>
79109
...
80-
</tree>
110+
</list>
81111
</field>
82112
...
83113
84-
With this example, column which renders 'name' field will have its **text** colored in white on customer records.
114+
With this example, column which renders 'name' field will have its
115+
**text** colored in white on customer records.
85116

86117
- If you want to use more than one color, you can split the attributes
87118
using ';':
88119

89-
::
90-
91-
options='{"fg_color": "red:red_color == True; green:green_color == True"}'
120+
::
92121

93-
Example:
122+
options='{"fg_color": "red:red_color == True; green:green_color == True"}'
94123

95-
.. code:: xml
124+
.. code:: xml
96125
97-
...
98-
<field name="arch" type="xml">
99-
<tree string="View name">
100-
...
101-
<field name="name" options='{"fg_color": "red:red_color == True; green:green_color == True"}'/>
102-
...
103-
</tree>
104-
</field>
105-
...
126+
...
127+
<field name="arch" type="xml">
128+
<list string="View name">
129+
...
130+
<field name="name" options='{"fg_color": "red:red_color == True; green:green_color == True"}'/>
131+
...
132+
</list>
133+
</field>
134+
...
106135
107-
- Can use strings too... In the tree view declaration, put
136+
- Can use strings too... In the list view declaration, put
108137
``options="{'fg_color': 'green:customer_state == \'success\''}"``
109138
attribute in the ``field`` tag:
110139

111-
::
140+
.. code:: xml
112141
113142
...
114143
<field name="arch" type="xml">
115-
<tree string="View name">
144+
<list string="View name">
116145
...
117146
<field name="name" options="{'fg_color': 'green:customer_state == \'success\''}"/>
118147
...
119-
</tree>
148+
</list>
120149
</field>
121150
...
122151
123152
**Note that you can use single or normal quotes. If the declaration of
124153
the options doesn't follow the JSON format, the options string will be
125154
evaluated using py.eval()**
126155

156+
Using view fields
157+
=================
158+
159+
- In the list view declaration, put
160+
``options='{"bg_color": "my_color"}`` attribute in the ``field`` tag:
161+
162+
.. code:: xml
163+
164+
...
165+
<field name="arch" type="xml">
166+
<list string="View name">
167+
...
168+
<field name="my_color" column_invisible="1"/>
169+
<field name="name" options='{"bg_color": "my_color"}'/>
170+
...
171+
</list>
172+
</field>
173+
...
174+
175+
With this example, the content of the field named ``my_color`` will be
176+
used to populate the ``background-color`` CSS value. Use a compute
177+
field to return whichever color you want depending on the other record
178+
values.
179+
127180
Known issues / Roadmap
128181
======================
129182

130-
- Before version 13.0, this module had a feature allowing to change the
131-
color of a line depending on a field, using a ``colors`` attribute
132-
with the name of the field on the ``<tree>`` element. Since 13.0, the
133-
``colors`` attribute is no longer in the RelaxNG schema of the tree
134-
view, so we can't use it anymore. This feature has then been dropped,
135-
but could be reimplement in another way.
136183
- Since version 17.0 coloring is written into ``style`` attribute of
137184
(td) element
138185

@@ -165,6 +212,7 @@ Contributors
165212
- Phuc Tran Thanh <[email protected]>
166213
- Sylvain LE GAL <https://twitter.com/legalsylvain>
167214
- Jurgis Pralgauskis <[email protected]>
215+
- Yann Papouin <[email protected]>
168216

169217
Other credits
170218
-------------

web_tree_dynamic_colored_field/__manifest__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
"author": "Camptocamp, Therp BV, Odoo Community Association (OCA)",
1010
"license": "AGPL-3",
1111
"website": "https://github.com/OCA/web",
12-
"demo": ["demo/res_users.xml"],
12+
"demo": [
13+
"demo/ir_config_parameter.xml",
14+
"demo/res_users.xml",
15+
"demo/res_groups.xml",
16+
],
1317
"installable": True,
1418
"assets": {
1519
"web.assets_backend": [
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<record id="view_ir_config_list" model="ir.ui.view">
4+
<field name="model">ir.config_parameter</field>
5+
<field name="inherit_id" ref="base.view_ir_config_list" />
6+
<field name="arch" type="xml">
7+
<field name="key" position="attributes">
8+
<attribute name="options">{
9+
"fg_color": "key",
10+
"bg_color": "value",
11+
}</attribute>
12+
</field>
13+
<field name="value" position="attributes">
14+
<attribute name="options">{
15+
"fg_color": "value",
16+
"bg_color": "key",
17+
}</attribute>
18+
</field>
19+
</field>
20+
</record>
21+
</odoo>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<record id="view_res_group_form" model="ir.ui.view">
4+
<field name="name">res.groups.form</field>
5+
<field name="model">res.groups</field>
6+
<field name="inherit_id" ref="base.view_groups_form" />
7+
<field name="arch" type="xml">
8+
<xpath expr="//page[@name='access_rights']//list" position="attributes">
9+
<attribute name="colors">bg_color_field: name</attribute>
10+
</xpath>
11+
</field>
12+
</record>
13+
</odoo>

web_tree_dynamic_colored_field/demo/res_users.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
<field name="arch" type="xml">
77
<field name="login_date" position="attributes">
88
<attribute name="options">{
9-
"bg_color": "#9e1635: login_date == False",
10-
"fg_color": "white: login_date == False"
11-
}</attribute>
9+
"bg_color": "#9e1635: login_date == False",
10+
"fg_color": "white: login_date == False"
11+
}</attribute>
1212
</field>
1313
<field name="name" position="attributes">
1414
<attribute name="options"> {
15-
"bg_color": "blue; #653b5b: login == 'admin'",
16-
"fg_color": "white"
17-
}</attribute>
15+
"bg_color": "blue; #653b5b: login == 'admin'",
16+
"fg_color": "white"
17+
}</attribute>
1818
</field>
1919
</field>
2020
</record>

web_tree_dynamic_colored_field/readme/CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
- Phuc Tran Thanh \<<[email protected]>\>
66
- Sylvain LE GAL \<<https://twitter.com/legalsylvain>\>
77
- Jurgis Pralgauskis \<<[email protected]>\>
8+
- Yann Papouin \<<[email protected]>\>
Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
1-
This module aims to add support for dynamically coloring fields in tree
2-
view according to data in the record.
1+
This module aims to add support for dynamically coloring fields in list view according
2+
to data in the record.
33

44
## Features
55

6-
- Add attribute `bg_color` on field's `options` to color background of a
7-
cell in tree view
8-
- Add attribute `fg_color` on field's `options` to change text color of
9-
a cell in tree view
6+
- Add attribute `bg_color` on field's `options` to color background of a cell in list
7+
view
8+
- Add attribute `fg_color` on field's `options` to change text color of a cell in list
9+
view
10+
- Add attribute `bg_color_field` on list's `colors` to change background color of the
11+
entire row in list view (\*)
12+
- Add attribute `fg_color_field` on list's `colors` to change text color of the entire
13+
row in list view (\*)
14+
15+
(\*) This functionality only works for a list defined in a form. (Since 13.0, the
16+
`colors` attribute is no longer in the RelaxNG schema of the list view, so we can't use
17+
it like before, but it looks like the RNG is not checked for embedded list.)
18+
19+
## Testing
20+
21+
Some views are overriden for demoing this module functionnalities:
22+
23+
1. On the Users list view: The `name` and `login_date` fields are colored according to
24+
conditions written in view definition.
25+
2. On the Groups form view > "Access Rights": By renaming the rule name to a color (red,
26+
blue, yellow, #00FDF0), the entire row background color is immediatly updated.
27+
3. On the System Parameters list view:
28+
- For the `key` field: Its content is the text color, the `value` field is its
29+
background color.
30+
- For the `value` field: Its content is the text color, the `value` field is its
31+
background color.
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
- Before version 13.0, this module had a feature allowing to change the
2-
color of a line depending on a field, using a `colors` attribute with
3-
the name of the field on the `<tree>` element. Since 13.0, the
4-
`colors` attribute is no longer in the RelaxNG schema of the tree
5-
view, so we can't use it anymore. This feature has then been dropped,
6-
but could be reimplement in another way.
71
- Since version 17.0 coloring is written into ``style`` attribute of (td) element

0 commit comments

Comments
 (0)