Browse Source

web_tree_dynamic_colored_field: Migration to 12.0

pull/1223/head
mreficent 5 years ago
parent
commit
7aab97208c
  1. 11
      web_tree_dynamic_colored_field/README.rst
  2. 1
      web_tree_dynamic_colored_field/__init__.py
  3. 2
      web_tree_dynamic_colored_field/__manifest__.py
  4. 4
      web_tree_dynamic_colored_field/readme/CONTRIBUTORS.rst
  5. 15
      web_tree_dynamic_colored_field/readme/DESCRIPTION.rst
  6. 67
      web_tree_dynamic_colored_field/readme/USAGE.rst
  7. 4
      web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js
  8. 2
      web_tree_dynamic_colored_field/views/web_tree_dynamic_colored_field.xml

11
web_tree_dynamic_colored_field/README.rst

@ -1,5 +1,5 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3
============================
@ -99,11 +99,16 @@ Bug Tracker
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/web/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing a detailed and welcomed feedback.
help us smash it by providing detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
Contributors
------------

1
web_tree_dynamic_colored_field/__init__.py

@ -1,2 +1 @@
# Copyright 2015-2018 Camptocamp SA, Damien Crier
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

2
web_tree_dynamic_colored_field/__manifest__.py

@ -4,7 +4,7 @@
'name': 'Colorize field in tree views',
'summary': 'Allows you to dynamically color fields on tree views',
'category': 'Hidden/Dependency',
'version': '11.0.1.0.1',
'version': '12.0.1.0.0',
'depends': ['web'],
'author': "Camptocamp, Therp BV, Odoo Community Association (OCA)",
'license': 'AGPL-3',

4
web_tree_dynamic_colored_field/readme/CONTRIBUTORS.rst

@ -0,0 +1,4 @@
* Damien Crier <damien.crier@camptocamp.com>
* Holger Brunn <hbrunn@therp.nl>
* Artem Kostyuk <a.kostyuk@mobilunity.com>
* Guewen Baconnier <guewen.baconnier@camptocamp.com>

15
web_tree_dynamic_colored_field/readme/DESCRIPTION.rst

@ -0,0 +1,15 @@
This module aims to add support for dynamically coloring fields in tree view
according to data in the record.
It provides attributes on fields with the similar syntax as the ``colors`` attribute
in tree tags.
Further, it provides a ``color_field`` attribute on tree tags's ``colors`` to use
a field's value as color.
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 ``color_field`` on the tree element's ``colors`` to use as color

67
web_tree_dynamic_colored_field/readme/USAGE.rst

@ -0,0 +1,67 @@
* In the tree view declaration, put ``options='{"bg_color": "red: customer==True"}`` attribute in the ``field`` tag::
...
<field name="arch" type="xml">
<tree string="View name">
...
<field name="name" options='{"bg_color": "red: customer == True"}'/>
...
</tree>
</field>
...
With this example, column which renders 'name' field will have its background colored in red.
* In the tree view declaration, put ``options='{"fg_color": "white:customer == True"}'`` attribute in the ``field`` tag::
...
<field name="arch" type="xml">
<tree string="View name">
...
<field name="name" options='{"fg_color": "white:customer == True"}'/>
...
</tree>
</field>
...
With this example, column which renders 'name' field will have its text colored in white on a customer records.
* In the tree view declaration, use ``options='"color_field": "my_color"'`` attribute in the ``tree`` tag::
...
<field name="arch" type="xml">
<tree string="View name" colors="color_field: my_color" >
...
<field name="my_color" invisible="1"/>
...
</tree>
</field>
...
* If you want to use more than one color, you can split the attributes using ';':
.. code::
options='{"fg_color": "red:red_color == True; green:green_color == True"}'
Example:
.. 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>
...
With this example, the content of the field named `my_color` will be used to
populate the `my_color` CSS value. Use a function field to return whichever
color you want depending on the other record values. Note that this
overrides the rest of `colors` attributes, and that you need the tree
to load your field in the first place by adding it as invisible field.
**Note that you should always use single quotes for fields' ``options`` and wrap nested values in double quotes since ``options`` is a JSON object.**

4
web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js

@ -13,7 +13,7 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
_renderBody: function () {
if (this.arch.attrs.colors) {
var colorAttr = this.arch.attrs.colors.split(';')
.filter(color => color.trim().startsWith('color_field'));
.filter(color >= color.trim().startsWith('color_field'));
if (colorAttr.length > 0) {
var colorField = colorAttr[0].split(':')[1].trim();
// validate the presence of that field in tree view
@ -90,7 +90,7 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
/**
* Parse `<color>: <field> <operator> <value>` forms to
* evaluatable expressions
* evaluable expressions
*
* @param {string} pairColor `color: expression` pair
*/

2
web_tree_dynamic_colored_field/views/web_tree_dynamic_colored_field.xml

@ -2,7 +2,7 @@
<odoo>
<template id="assets_backend" name="web_tree_dynamic_colored_field assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js"></script>
<script type="text/javascript" src="/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js"/>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save