diff --git a/base_view_inheritance_extension/README.rst b/base_view_inheritance_extension/README.rst index b17b13b62..dd061a36e 100644 --- a/base_view_inheritance_extension/README.rst +++ b/base_view_inheritance_extension/README.rst @@ -14,13 +14,13 @@ Extended view inheritance :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html :alt: License: LGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github - :target: https://github.com/OCA/server-tools/tree/12.0/base_view_inheritance_extension + :target: https://github.com/OCA/server-tools/tree/13.0/base_view_inheritance_extension :alt: OCA/server-tools .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-base_view_inheritance_extension + :target: https://translation.odoo-community.org/projects/server-tools-13-0/server-tools-13-0-base_view_inheritance_extension :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/149/12.0 + :target: https://runbot.odoo-community.org/runbot/149/13.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -68,8 +68,6 @@ to refer to some xmlid, say ``%(xmlid)s``. This feature is now native, cf the `official Odoo documentation `_. - - Known issues / Roadmap ====================== @@ -83,7 +81,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -115,6 +113,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/server-tools `_ project on GitHub. +This module is part of the `OCA/server-tools `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_view_inheritance_extension/__manifest__.py b/base_view_inheritance_extension/__manifest__.py index f1c8ea16b..bebdffffc 100644 --- a/base_view_inheritance_extension/__manifest__.py +++ b/base_view_inheritance_extension/__manifest__.py @@ -3,7 +3,7 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). { "name": "Extended view inheritance", - "version": "12.0.1.0.0", + "version": "13.0.1.0.0", "author": "Therp BV,Odoo Community Association (OCA)", "license": "LGPL-3", "category": "Hidden/Dependency", diff --git a/base_view_inheritance_extension/demo/ir_ui_view.xml b/base_view_inheritance_extension/demo/ir_ui_view.xml index fb357c955..e40a4a98b 100644 --- a/base_view_inheritance_extension/demo/ir_ui_view.xml +++ b/base_view_inheritance_extension/demo/ir_ui_view.xml @@ -1,25 +1,33 @@ - + - - res.partner - - - - Partner form - - - 'The company name' - context.get('company_id', context.get('company')) - - - - parent_id - -
- - - -
+ + res.partner + + + + Partner form + + + 'The company name' + context.get('company_id', context.get('company')) - + + + parent_id + +
+ + + +
+
+
diff --git a/base_view_inheritance_extension/models/ir_ui_view.py b/base_view_inheritance_extension/models/ir_ui_view.py index d09f75ab8..4f5fc0f2d 100644 --- a/base_view_inheritance_extension/models/ir_ui_view.py +++ b/base_view_inheritance_extension/models/ir_ui_view.py @@ -2,9 +2,9 @@ # Copyright 2018 Tecnativa - Sergio Teruel # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from lxml import etree +from yaml import safe_load from odoo import api, models, tools -from odoo.tools.safe_eval import safe_eval class UnquoteObject(str): @@ -78,6 +78,24 @@ class IrUiView(models.Model): ) return handler + def _is_variable(self, value): + return not ("'" in value or '"' in value) and True or False + + def _list_variables(self, str_dict): + """ + Store non literal dictionary values into a list to post-process + operations. + """ + variables = [] + items = str_dict.replace("{", "").replace("}", "").split(",") + for item in items: + key_value = item.split(":") + if len(key_value) == 2: + value = key_value[1] + if self._is_variable(value): + variables.append(value.strip()) + return variables + @api.model def inheritance_handler_attributes_python_dict(self, source, specs, inherit_id): """Implement @@ -88,13 +106,15 @@ class IrUiView(models.Model): """ node = self.locate_node(source, specs) for attribute_node in specs: - python_dict = safe_eval( - node.get(attribute_node.get("name")) or "{}", - UnquoteEvalObjectContext(), - nocopy=True, - ) - python_dict[attribute_node.get("key")] = UnquoteObject(attribute_node.text) - node.attrib[attribute_node.get("name")] = str(python_dict) + str_dict = node.get(attribute_node.get("name")) or "{}" + variables = self._list_variables(str_dict) + if self._is_variable(attribute_node.text): + variables.append(attribute_node.text) + my_dict = safe_load(str_dict) + my_dict[attribute_node.get("key")] = attribute_node.text + for k, v in my_dict.items(): + my_dict[k] = UnquoteObject(v) if v in variables else v + node.attrib[attribute_node.get("name")] = str(my_dict) return source @api.model diff --git a/base_view_inheritance_extension/static/description/index.html b/base_view_inheritance_extension/static/description/index.html index e52ac987a..df01acd10 100644 --- a/base_view_inheritance_extension/static/description/index.html +++ b/base_view_inheritance_extension/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: LGPL-3 OCA/server-tools Translate me on Weblate Try me on Runbot

+

Beta License: LGPL-3 OCA/server-tools Translate me on Weblate Try me on Runbot

This module was written to make it simple to add custom operators for view inheritance.

Table of contents

@@ -422,7 +422,7 @@ to refer to some xmlid, say %(xmlid)s.

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -448,7 +448,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

-

This module is part of the OCA/server-tools project on GitHub.

+

This module is part of the OCA/server-tools project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/base_view_inheritance_extension/tests/test_base_view_inheritance_extension.py b/base_view_inheritance_extension/tests/test_base_view_inheritance_extension.py index 25f29e539..1a9223fc4 100644 --- a/base_view_inheritance_extension/tests/test_base_view_inheritance_extension.py +++ b/base_view_inheritance_extension/tests/test_base_view_inheritance_extension.py @@ -90,3 +90,42 @@ class TestBaseViewInheritanceExtension(TransactionCase): ) button_node = modified_source.xpath('//button[@name="test"]')[0] self.assertEqual(button_node.attrib["states"], "draft,valid,paid") + + def test_python_dict_inheritance(self): + view_model = self.env["ir.ui.view"] + inherit_id = self.env.ref("base.view_partner_form").id + source = etree.fromstring( + """
+ + """ + ) + specs = etree.fromstring( + """\ + + my_value + 'my name' + cost_center_id + + """ + ) + modified_source = view_model.inheritance_handler_attributes_python_dict( + source, specs, inherit_id + ) + field_node = modified_source.xpath('//field[@name="invoice_line_ids"]')[0] + self.assertTrue( + "currency_id != company_currency_id and currency_id or False" + in field_node.attrib["context"] + ) + self.assertTrue("my_value" in field_node.attrib["context"]) + self.assertFalse("'cost_center_id'" in field_node.attrib["context"])