Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 85 additions & 37 deletions web_tree_dynamic_colored_field/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,42 @@ Colorize field in tree views

|badge1| |badge2| |badge3| |badge4| |badge5|

This module aims to add support for dynamically coloring fields in tree
This module aims to add support for dynamically coloring fields in list
view according to data in the record.

Features
--------

- Add attribute ``bg_color`` on field's ``options`` to color background
of a cell in tree view
of a cell in list view
- Add attribute ``fg_color`` on field's ``options`` to change text color
of a cell in tree view
of a cell in list view
- Add attribute ``bg_color_field`` on list's ``colors`` to change
background color of the entire row in list view (\*)
- Add attribute ``fg_color_field`` on list's ``colors`` to change text
color of the entire row in list view (\*)

(\*) This functionality only works for a list defined in a form. (Since
13.0, the ``colors`` attribute is no longer in the RelaxNG schema of the
list view, so we can't use it like before, but it looks like the RNG is
not checked for embedded list.)

Testing
-------

Some views are overriden for demoing this module functionnalities:

1. On the Users list view: The ``name`` and ``login_date`` fields are
colored according to conditions written in view definition.
2. On the Groups form view > "Access Rights": By renaming the rule name
to a color (red, blue, yellow, #00FDF0), the entire row background
color is immediatly updated.
3. On the System Parameters list view:

- For the ``key`` field: Its content is the text color, the ``value``
field is its background color.
- For the ``value`` field: Its content is the text color, the
``value`` field is its background color.

**Table of contents**

Expand All @@ -47,92 +73,113 @@ Features
Usage
=====

- In the tree view declaration, put
Using view conditions
=====================

- In the list view declaration, put
``options='{"bg_color": "red: customer==True"}`` attribute in the
``field`` tag:

::
.. code:: xml

...
<field name="arch" type="xml">
<tree string="View name">
<list string="View name">
...
<field name="name" options='{"bg_color": "red: customer == True"}'/>
...
</tree>
</list>
</field>
...

With this example, column which renders 'name' field will have its **background** colored in red on customer records.
With this example, column which renders 'name' field will have its
**background** colored in red on customer records.

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

::
.. code:: xml

...
<field name="arch" type="xml">
<tree string="View name">
<list string="View name">
...
<field name="name" options='{"fg_color": "white:customer == True"}'/>
...
</tree>
</list>
</field>
...

With this example, column which renders 'name' field will have its **text** colored in white on customer records.
With this example, column which renders 'name' field will have its
**text** colored in white on customer records.

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

::

options='{"fg_color": "red:red_color == True; green:green_color == True"}'
::

Example:
options='{"fg_color": "red:red_color == True; green:green_color == True"}'

.. code:: xml
.. code:: xml

...
<field name="arch" type="xml">
<tree string="View name">
...
<field name="name" options='{"fg_color": "red:red_color == True; green:green_color == True"}'/>
...
</tree>
</field>
...
...
<field name="arch" type="xml">
<list string="View name">
...
<field name="name" options='{"fg_color": "red:red_color == True; green:green_color == True"}'/>
...
</list>
</field>
...

- Can use strings too... In the tree view declaration, put
- Can use strings too... In the list view declaration, put
``options="{'fg_color': 'green:customer_state == \'success\''}"``
attribute in the ``field`` tag:

::
.. code:: xml

...
<field name="arch" type="xml">
<tree string="View name">
<list string="View name">
...
<field name="name" options="{'fg_color': 'green:customer_state == \'success\''}"/>
...
</tree>
</list>
</field>
...

**Note that you can use single or normal quotes. If the declaration of
the options doesn't follow the JSON format, the options string will be
evaluated using py.eval()**

Using view fields
=================

- In the list view declaration, put
``options='{"bg_color": "my_color"}`` attribute in the ``field`` tag:

.. code:: xml

...
<field name="arch" type="xml">
<list string="View name">
...
<field name="my_color" column_invisible="1"/>
<field name="name" options='{"bg_color": "my_color"}'/>
...
</list>
</field>
...

With this example, the content of the field named ``my_color`` will be
used to populate the ``background-color`` CSS value. Use a compute
field to return whichever color you want depending on the other record
values.

Known issues / Roadmap
======================

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

Expand Down Expand Up @@ -165,6 +212,7 @@ Contributors
- Phuc Tran Thanh <phuc@trobz.com>
- Sylvain LE GAL <https://twitter.com/legalsylvain>
- Jurgis Pralgauskis <jurgis@versada.eu>
- Yann Papouin <ypa@decgroupe.com>

Other credits
-------------
Expand Down
6 changes: 5 additions & 1 deletion web_tree_dynamic_colored_field/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"author": "Camptocamp, Therp BV, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/web",
"demo": ["demo/res_users.xml"],
"demo": [
"demo/ir_config_parameter.xml",
"demo/res_users.xml",
"demo/res_groups.xml",
],
"installable": True,
"assets": {
"web.assets_backend": [
Expand Down
21 changes: 21 additions & 0 deletions web_tree_dynamic_colored_field/demo/ir_config_parameter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_ir_config_list" model="ir.ui.view">
<field name="model">ir.config_parameter</field>
<field name="inherit_id" ref="base.view_ir_config_list" />
<field name="arch" type="xml">
<field name="key" position="attributes">
<attribute name="options">{
"fg_color": "key",
"bg_color": "value",
}</attribute>
</field>
<field name="value" position="attributes">
<attribute name="options">{
"fg_color": "value",
"bg_color": "key",
}</attribute>
</field>
</field>
</record>
</odoo>
13 changes: 13 additions & 0 deletions web_tree_dynamic_colored_field/demo/res_groups.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_res_group_form" model="ir.ui.view">
<field name="name">res.groups.form</field>
<field name="model">res.groups</field>
<field name="inherit_id" ref="base.view_groups_form" />
<field name="arch" type="xml">
<xpath expr="//page[@name='access_rights']//list" position="attributes">
<attribute name="colors">bg_color_field: name</attribute>
</xpath>
</field>
</record>
</odoo>
12 changes: 6 additions & 6 deletions web_tree_dynamic_colored_field/demo/res_users.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<field name="arch" type="xml">
<field name="login_date" position="attributes">
<attribute name="options">{
"bg_color": "#9e1635: login_date == False",
"fg_color": "white: login_date == False"
}</attribute>
"bg_color": "#9e1635: login_date == False",
"fg_color": "white: login_date == False"
}</attribute>
</field>
<field name="name" position="attributes">
<attribute name="options"> {
"bg_color": "blue; #653b5b: login == 'admin'",
"fg_color": "white"
}</attribute>
"bg_color": "blue; #653b5b: login == 'admin'",
"fg_color": "white"
}</attribute>
</field>
</field>
</record>
Expand Down
1 change: 1 addition & 0 deletions web_tree_dynamic_colored_field/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
- Phuc Tran Thanh \<<phuc@trobz.com>\>
- Sylvain LE GAL \<<https://twitter.com/legalsylvain>\>
- Jurgis Pralgauskis \<<jurgis@versada.eu>\>
- Yann Papouin \<<ypa@decgroupe.com>\>
34 changes: 28 additions & 6 deletions web_tree_dynamic_colored_field/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
This module aims to add support for dynamically coloring fields in tree
view according to data in the record.
This module aims to add support for dynamically coloring fields in list view according
to data in the record.

## Features

- Add attribute `bg_color` on field's `options` to color background of a
cell in tree view
- Add attribute `fg_color` on field's `options` to change text color of
a cell in tree view
- Add attribute `bg_color` on field's `options` to color background of a cell in list
view
- Add attribute `fg_color` on field's `options` to change text color of a cell in list
view
- Add attribute `bg_color_field` on list's `colors` to change background color of the
entire row in list view (\*)
- Add attribute `fg_color_field` on list's `colors` to change text color of the entire
row in list view (\*)

(\*) This functionality only works for a list defined in a form. (Since 13.0, the
`colors` attribute is no longer in the RelaxNG schema of the list view, so we can't use
it like before, but it looks like the RNG is not checked for embedded list.)

## Testing

Some views are overriden for demoing this module functionnalities:

1. On the Users list view: The `name` and `login_date` fields are colored according to
conditions written in view definition.
2. On the Groups form view > "Access Rights": By renaming the rule name to a color (red,
blue, yellow, #00FDF0), the entire row background color is immediatly updated.
3. On the System Parameters list view:
- For the `key` field: Its content is the text color, the `value` field is its
background color.
- For the `value` field: Its content is the text color, the `value` field is its
background color.
6 changes: 0 additions & 6 deletions web_tree_dynamic_colored_field/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
- Before version 13.0, this module had a feature allowing to change the
color of a line depending on a field, using a `colors` attribute with
the name of the field on the `<tree>` element. Since 13.0, the
`colors` attribute is no longer in the RelaxNG schema of the tree
view, so we can't use it anymore. This feature has then been dropped,
but could be reimplement in another way.
- Since version 17.0 coloring is written into ``style`` attribute of (td) element
Loading