From 1a06367d4927fada56b58f1b5544fb310117b18a Mon Sep 17 00:00:00 2001
From: Guewen Baconnier <guewen.baconnier@camptocamp.com>
Date: Thu, 9 Jan 2020 14:44:28 +0100
Subject: [PATCH] [MIG] web_tree_dynamic_colored_field: Migration to 13.0

Use 'options' instead of 'colors' on tree views

The colors attribute has been removed from the RelaxNG schema in
Odoo [0], so use the 'options' instead.

Closes #1479

[0] https://github.com/odoo/odoo/commit/7024f8d58bb279c800818955979ab73f1ee7b612#diff-e9acd2f731cc01f302055b6e232df983
---
 web_tree_dynamic_colored_field/__manifest__.py      |  2 +-
 web_tree_dynamic_colored_field/demo/res_users.xml   |  2 +-
 .../readme/DESCRIPTION.rst                          |  6 +++---
 web_tree_dynamic_colored_field/readme/USAGE.rst     |  4 ++--
 .../static/src/js/web_tree_dynamic_colored_field.js | 13 ++++++++-----
 5 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/web_tree_dynamic_colored_field/__manifest__.py b/web_tree_dynamic_colored_field/__manifest__.py
index 3cda70693..3fc8257fc 100644
--- a/web_tree_dynamic_colored_field/__manifest__.py
+++ b/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": "12.0.1.0.0",
+    "version": "13.0.1.0.0",
     "depends": ["web"],
     "author": "Camptocamp, Therp BV, Odoo Community Association (OCA)",
     "license": "AGPL-3",
diff --git a/web_tree_dynamic_colored_field/demo/res_users.xml b/web_tree_dynamic_colored_field/demo/res_users.xml
index ef364722f..dd8afbb00 100644
--- a/web_tree_dynamic_colored_field/demo/res_users.xml
+++ b/web_tree_dynamic_colored_field/demo/res_users.xml
@@ -5,7 +5,7 @@
         <field name="inherit_id" ref="base.view_users_tree" />
         <field name="arch" type="xml">
           <tree position="attributes">
-            <attribute name="colors">color_field: lang</attribute>
+            <attribute name="options">{"color_field": "lang"}</attribute>
           </tree>
           <field name="login_date" position="attributes">
             <attribute name="options">{
diff --git a/web_tree_dynamic_colored_field/readme/DESCRIPTION.rst b/web_tree_dynamic_colored_field/readme/DESCRIPTION.rst
index c3f632caa..c9ae98dcf 100644
--- a/web_tree_dynamic_colored_field/readme/DESCRIPTION.rst
+++ b/web_tree_dynamic_colored_field/readme/DESCRIPTION.rst
@@ -1,10 +1,10 @@
 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
+It provides attributes on fields with a similar syntax as the ``colors`` attribute
 in tree tags.
 
-Further, it provides a ``color_field`` attribute on tree tags's ``colors`` to use
+Further, it provides a ``color_field`` attribute on tree tags's ``options`` to use
 a field's value as color.
 
 Features
@@ -12,4 +12,4 @@ 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
+* Add attribute ``color_field`` on the tree element's ``options`` to use as color
diff --git a/web_tree_dynamic_colored_field/readme/USAGE.rst b/web_tree_dynamic_colored_field/readme/USAGE.rst
index 921a3262c..101802d9b 100644
--- a/web_tree_dynamic_colored_field/readme/USAGE.rst
+++ b/web_tree_dynamic_colored_field/readme/USAGE.rst
@@ -26,11 +26,11 @@
 
     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::
+* 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" >
+        <tree string="View name" options='{"color_field": "my_color"}' >
             ...
             <field name="my_color" invisible="1"/>
             ...
diff --git a/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js b/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js
index b1aa0407c..f2a4f99a6 100644
--- a/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js
+++ b/web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js
@@ -11,11 +11,14 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
          * @override
          */
         _renderBody: function () {
-            if (this.arch.attrs.colors) {
-                var colorAttr = this.arch.attrs.colors.split(';');
-                if (colorAttr.length > 0) {
-                    var colorField = colorAttr[0].split(':')[1].trim();
-                    // validate the presence of that field in tree view
+            if (this.arch.attrs.options) {
+                var archOptions = this.arch.attrs.options;
+                if (!_.isObject(archOptions)) {
+                    archOptions = pyUtils.py_eval(archOptions);
+                }
+                var colorField = archOptions.color_field;
+                if (colorField) {
+                    // Validate the presence of that field in tree view
                     if (this.state.data.length && colorField in this.state.data[0].data) {
                         this.colorField = colorField;
                     } else {