# HG changeset patch
# User Houzefa Abbasbhay <houzefa.abba@xcg-consulting.fr>
# Date 1579513837 -3600
#      Mon Jan 20 10:50:37 2020 +0100
# Branch 11.0-tomerge
# Node ID b422df8b2dfe0c85ebff3039a9e03c89df2eabb3
# Parent  4fd3d3f64d452ba3472e7ceda387567f6a39ef2c
Fix dynamic field attributes (column_invisible)

diff --git a/models/analytic_structure.py b/models/analytic_structure.py
--- a/models/analytic_structure.py
+++ b/models/analytic_structure.py
@@ -299,7 +299,7 @@
             else:
                 # No analytic structure defined for this field, hide it.
                 modifiers = json.loads(match.get("modifiers", "{}"))
-                modifiers["invisible"] = modifiers["tree_invisible"] = True
+                modifiers["invisible"] = modifiers["column_invisible"] = True
                 modifiers["required"] = False
                 match.set("invisible", "true")
                 match.set("required", "false")
@@ -345,20 +345,28 @@
                 )
                 view["fields"].update(elem_fields_def)
 
+                # Prepare the "modifiers" attribute normally dynamically added.
+                # Specifics here:
+                # * We compare against explicit attributes in the view. This
+                #   way we avoid all-read-only fields as the main
+                #   "analytic_dimensions" pseudo-field is read-only.
+                # * When comparing, handle column_invisible -> invisible (see
+                #   odoo/osv/orm.py > transfer_node_to_modifiers).
                 modifiers = json.loads(elem.attrib.get("modifiers", "{}"))
+                modifiers = json.dumps(
+                    {
+                        attr: value
+                        for attr, value in modifiers.items()
+                        if elem.attrib.get(_MODIFIER_TO_ATTR.get(attr, attr))
+                        in ("True", "true", "1")
+                    }
+                )
+
                 # Now we can insert the fields in the view's architecture.
                 for field in elem_fields:
-                    attrs = {"name": field}
-                    attrs["modifiers"] = json.dumps(
-                        {
-                            attr: value
-                            for attr, value in list(modifiers.items())
-                            if elem.attrib.get(attr, "False")
-                            in ("True", "true", "1")
-                        }
-                    )
-                    for attr, value in list(elem.attrib.items()):
-                        if attr in ["name", "prefix", "suffix", "modifiers"]:
+                    attrs = {"modifiers": modifiers, "name": field}
+                    for attr, value in elem.attrib.items():
+                        if attr in ("name", "prefix", "suffix", "modifiers"):
                             continue
                         attrs[attr] = value
                     parent.append(etree.Element("field", attrs))
@@ -368,3 +376,8 @@
         view["arch"] = etree.tostring(doc)
 
         return view
+
+
+# Used above in analytic_fields_view_get to compare "modifiers" vs explicit
+# attributes. See odoo/osv/orm.py > transfer_node_to_modifiers.
+_MODIFIER_TO_ATTR = {"column_invisible": "invisible"}