From 016864ce6b9cb6089ca4f7c3d56e9bf948c98d0b Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Thu, 15 Dec 2022 12:30:22 +0000 Subject: [PATCH] [FIX] base: standardize modifiers received by the JS Framework Before this commit, the JS Framework receives different types of modifiers: - List: used for domains. - String: used for the dynamic domains and boolean values ('1' or '0'); - Integer: used for boolean values (1 or 0); - Boolean: used for boolean values (True or False); The issue with this, is that the JS Framework needed to manage the 3 different possibles ways to have a boolean modifier (1, '1', True). Now, only three types are sent to the JS Framework: - List: used for domains. - String: used for the dynamic domains and boolean values ('1' or '0'); - Boolean: used for boolean values (True or False). The boolean usually sent in a Number (1 or 0) will be transformed into proper Boolean types (True or False).\ Note that, the 'falsy' modifiers are not sent to the JS Framework. closes odoo/odoo#108095 X-original-commit: faddb53f30b94ac47ffd7b3b1af36f094f3a60f6 Signed-off-by: Julien Castiaux Signed-off-by: Jorge Pinna Puissant (jpp) --- odoo/addons/base/models/ir_ui_view.py | 3 +++ odoo/addons/base/tests/test_views.py | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index 48d051a24c2..dd3b9391db9 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -84,6 +84,9 @@ def transfer_node_to_modifiers(node, modifiers): attrs = node.attrib.pop('attrs', None) if attrs: modifiers.update(ast.literal_eval(attrs.strip())) + for a in ('invisible', 'readonly', 'required'): + if a in modifiers and isinstance(modifiers[a], int): + modifiers[a] = bool(modifiers[a]) states = node.attrib.pop('states', None) if states: diff --git a/odoo/addons/base/tests/test_views.py b/odoo/addons/base/tests/test_views.py index 4ee19f5d3b6..15ac8377fe7 100644 --- a/odoo/addons/base/tests/test_views.py +++ b/odoo/addons/base/tests/test_views.py @@ -1792,7 +1792,7 @@ class TestViews(ViewCase): node = etree.fromstring(what) if isinstance(what, str) else what transfer_node_to_modifiers(node, modifiers) simplify_modifiers(modifiers) - assert modifiers == expected, "%s != %s" % (modifiers, expected) + assert str(modifiers) == str(expected), "%s != %s" % (modifiers, expected) _test_modifiers('', {}) _test_modifiers('', {"invisible": True}) @@ -1801,6 +1801,14 @@ class TestViews(ViewCase): _test_modifiers('', {}) _test_modifiers('', {}) _test_modifiers('', {}) + _test_modifiers( + """""", + {"readonly": True}, + ) + _test_modifiers( + """""", + {}, + ) # TODO: Order is not guaranteed _test_modifiers( '',