Skip to content
Snippets Groups Projects
Commit 191d5560a4ba authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:handshake: 11.0-tomerge

No related branches found
No related tags found
1 merge request!14🤝 11.0-tomerge
Pipeline #45188 passed
This commit is part of merge request !14. Comments created here will be created in the context of that merge request.
...@@ -155,6 +155,18 @@ ...@@ -155,6 +155,18 @@
@AddMethod(superclass) @AddMethod(superclass)
@api.model @api.model
def get_analytic_field_names(self):
field_names = []
analytic_osv = self.env["analytic.structure"]
for model_name, prefix, suffix in all_analytic:
for ordering in analytic_osv.get_dimensions_names(model_name):
field_names.append("%s%s_%s" % (prefix, ordering, suffix))
return field_names
@AddMethod(superclass)
@api.model
def fields_get(self, allfields=None, attributes=None): def fields_get(self, allfields=None, attributes=None):
"""Override this method to rename analytic fields.""" """Override this method to rename analytic fields."""
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
- code_description - code_description
- parent_column - parent_column
New partners without name, does not trigger an analytic_code creation. New partners without name, does not trigger an analytic_code creation.
Added a method able to return the technical names of all the analytic fields of
a class.
.. _2.2: .. _2.2:
......
...@@ -101,6 +101,10 @@ ...@@ -101,6 +101,10 @@
.. _AnalyticFields: .. _AnalyticFields:
This metaclass adds a method able to return the technical names of all the
analytic fields of the inheriting class:
.. get_analytic_field_names
Add analytic fields to a model Add analytic fields to a model
------------------------------ ------------------------------
......
...@@ -300,7 +300,7 @@ ...@@ -300,7 +300,7 @@
else: else:
# No analytic structure defined for this field, hide it. # No analytic structure defined for this field, hide it.
modifiers = json.loads(match.get("modifiers", "{}")) modifiers = json.loads(match.get("modifiers", "{}"))
modifiers["invisible"] = modifiers["tree_invisible"] = True modifiers["invisible"] = modifiers["column_invisible"] = True
modifiers["required"] = False modifiers["required"] = False
match.set("invisible", "true") match.set("invisible", "true")
match.set("required", "false") match.set("required", "false")
...@@ -346,4 +346,11 @@ ...@@ -346,4 +346,11 @@
) )
view["fields"].update(elem_fields_def) 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.loads(elem.attrib.get("modifiers", "{}"))
...@@ -349,4 +356,13 @@ ...@@ -349,4 +356,13 @@
modifiers = json.loads(elem.attrib.get("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. # Now we can insert the fields in the view's architecture.
model_map = { model_map = {
...@@ -382,3 +398,8 @@ ...@@ -382,3 +398,8 @@
view["arch"] = etree.tostring(doc) view["arch"] = etree.tostring(doc)
return view 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"}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment