You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
5.5 KiB

  1. ============================
  2. Colorize field in tree views
  3. ============================
  4. .. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5. !! This file is generated by oca-gen-addon-readme !!
  6. !! changes will be overwritten. !!
  7. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8. .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
  9. :target: https://odoo-community.org/page/development-status
  10. :alt: Beta
  11. .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
  12. :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
  13. :alt: License: AGPL-3
  14. .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
  15. :target: https://github.com/OCA/web/tree/12.0/web_tree_dynamic_colored_field
  16. :alt: OCA/web
  17. .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
  18. :target: https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_tree_dynamic_colored_field
  19. :alt: Translate me on Weblate
  20. .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
  21. :target: https://runbot.odoo-community.org/runbot/162/12.0
  22. :alt: Try me on Runbot
  23. |badge1| |badge2| |badge3| |badge4| |badge5|
  24. This module aims to add support for dynamically coloring fields in tree view
  25. according to data in the record.
  26. It provides attributes on fields with the similar syntax as the ``colors`` attribute
  27. in tree tags.
  28. Further, it provides a ``color_field`` attribute on tree tags's ``colors`` to use
  29. a field's value as color.
  30. Features
  31. ========
  32. * Add attribute ``bg_color`` on field's ``options`` to color background of a cell in tree view
  33. * Add attribute ``fg_color`` on field's ``options`` to change text color of a cell in tree view
  34. * Add attribute ``color_field`` on the tree element's ``colors`` to use as color
  35. **Table of contents**
  36. .. contents::
  37. :local:
  38. Usage
  39. =====
  40. * In the tree view declaration, put ``options='{"bg_color": "red: customer==True"}`` attribute in the ``field`` tag::
  41. ...
  42. <field name="arch" type="xml">
  43. <tree string="View name">
  44. ...
  45. <field name="name" options='{"bg_color": "red: customer == True"}'/>
  46. ...
  47. </tree>
  48. </field>
  49. ...
  50. With this example, column which renders 'name' field will have its background colored in red.
  51. * In the tree view declaration, put ``options='{"fg_color": "white:customer == True"}'`` attribute in the ``field`` tag::
  52. ...
  53. <field name="arch" type="xml">
  54. <tree string="View name">
  55. ...
  56. <field name="name" options='{"fg_color": "white:customer == True"}'/>
  57. ...
  58. </tree>
  59. </field>
  60. ...
  61. With this example, column which renders 'name' field will have its text colored in white on a customer records.
  62. * In the tree view declaration, use ``options='"color_field": "my_color"'`` attribute in the ``tree`` tag::
  63. ...
  64. <field name="arch" type="xml">
  65. <tree string="View name" colors="color_field: my_color" >
  66. ...
  67. <field name="my_color" invisible="1"/>
  68. ...
  69. </tree>
  70. </field>
  71. ...
  72. * If you want to use more than one color, you can split the attributes using ';':
  73. .. code::
  74. options='{"fg_color": "red:red_color == True; green:green_color == True"}'
  75. Example:
  76. .. code:: xml
  77. ...
  78. <field name="arch" type="xml">
  79. <tree string="View name">
  80. ...
  81. <field name="name" options='{"fg_color": "red:red_color == True; green:green_color == True"}'/>
  82. ...
  83. </tree>
  84. </field>
  85. ...
  86. With this example, the content of the field named `my_color` will be used to
  87. populate the `my_color` CSS value. Use a function field to return whichever
  88. color you want depending on the other record values. Note that this
  89. overrides the rest of `colors` attributes, and that you need the tree
  90. to load your field in the first place by adding it as invisible field.
  91. **Note that you should always use single quotes for fields' ``options`` and wrap nested values in double quotes since ``options`` is a JSON object.**
  92. Bug Tracker
  93. ===========
  94. Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
  95. In case of trouble, please check there if your issue has already been reported.
  96. If you spotted it first, help us smashing it by providing a detailed and welcomed
  97. `feedback <https://github.com/OCA/web/issues/new?body=module:%20web_tree_dynamic_colored_field%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
  98. Do not contact contributors directly about support or help with technical issues.
  99. Credits
  100. =======
  101. Authors
  102. ~~~~~~~
  103. * Camptocamp
  104. * Therp BV
  105. Contributors
  106. ~~~~~~~~~~~~
  107. * Damien Crier <damien.crier@camptocamp.com>
  108. * Holger Brunn <hbrunn@therp.nl>
  109. * Artem Kostyuk <a.kostyuk@mobilunity.com>
  110. * Guewen Baconnier <guewen.baconnier@camptocamp.com>
  111. Maintainers
  112. ~~~~~~~~~~~
  113. This module is maintained by the OCA.
  114. .. image:: https://odoo-community.org/logo.png
  115. :alt: Odoo Community Association
  116. :target: https://odoo-community.org
  117. OCA, or the Odoo Community Association, is a nonprofit organization whose
  118. mission is to support the collaborative development of Odoo features and
  119. promote its widespread use.
  120. This module is part of the `OCA/web <https://github.com/OCA/web/tree/12.0/web_tree_dynamic_colored_field>`_ project on GitHub.
  121. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.