diff --git a/base_view_inheritance_extension/README.rst b/base_view_inheritance_extension/README.rst new file mode 100644 index 000000000..8844edc2e --- /dev/null +++ b/base_view_inheritance_extension/README.rst @@ -0,0 +1,123 @@ +========================= +Extended view inheritance +========================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :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/11.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-11-0/server-tools-11-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/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module was written to make it simple to add custom operators for view +inheritance. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +**Change a python dictionary (context for example)** + + +.. code-block:: xml + + + $new_value + + +Note that views are subject to evaluation of xmlids anyways, so if you need +to refer to some xmlid, say ``%(xmlid)s``. + +**Move an element in the view** + +.. code-block:: xml + + + +This can also be used to wrap some element into another, create the target +element first, then move the node youwant to wrap there. + +**Add to values in a list (states for example)** + +.. code-block:: xml + + + $new_value(s) + + +**Remove values from a list (states for example)** + +.. code-block:: xml + + + $remove_value(s) + + +Known issues / Roadmap +====================== + +* add ``$value`` +* support ```` +* support an ``eval`` attribute for our new node types + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Therp BV + +Contributors +~~~~~~~~~~~~ + +* Holger Brunn +* Ronald Portier +* Sergio Teruel + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_view_inheritance_extension/__init__.py b/base_view_inheritance_extension/__init__.py new file mode 100644 index 000000000..92325983c --- /dev/null +++ b/base_view_inheritance_extension/__init__.py @@ -0,0 +1,2 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +from . import models diff --git a/base_view_inheritance_extension/__manifest__.py b/base_view_inheritance_extension/__manifest__.py new file mode 100644 index 000000000..27a24017e --- /dev/null +++ b/base_view_inheritance_extension/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2016 Therp BV +# Copyright 2018 Tecnativa - Sergio Teruel +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +{ + "name": "Extended view inheritance", + "version": "11.0.1.0.0", + "author": "Therp BV,Odoo Community Association (OCA)", + "license": "LGPL-3", + "category": "Hidden/Dependency", + "summary": "Adds more operators for view inheritance", + "depends": [ + 'base', + ], + "demo": [ + "demo/ir_ui_view.xml", + ], +} diff --git a/base_view_inheritance_extension/demo/ir_ui_view.xml b/base_view_inheritance_extension/demo/ir_ui_view.xml new file mode 100644 index 000000000..043960209 --- /dev/null +++ b/base_view_inheritance_extension/demo/ir_ui_view.xml @@ -0,0 +1,27 @@ + + + + res.partner + + + + Partner form + + + 'The company name' + context.get('company_id', context.get('company')) + + + + parent_id + +
+ + + +
+ + +
+
+
diff --git a/base_view_inheritance_extension/i18n/base_view_inheritance_extension.pot b/base_view_inheritance_extension/i18n/base_view_inheritance_extension.pot new file mode 100644 index 000000000..6a43a709f --- /dev/null +++ b/base_view_inheritance_extension/i18n/base_view_inheritance_extension.pot @@ -0,0 +1,30 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_view_inheritance_extension +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Partner form" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Phone numbers" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "ir.ui.view" +msgstr "" + diff --git a/base_view_inheritance_extension/i18n/ca.po b/base_view_inheritance_extension/i18n/ca.po new file mode 100644 index 000000000..fef50e279 --- /dev/null +++ b/base_view_inheritance_extension/i18n/ca.po @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_view_inheritance_extension +# +# Translators: +# Marc Tormo i Bochaca , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-04-19 17:59+0000\n" +"PO-Revision-Date: 2017-04-19 17:59+0000\n" +"Last-Translator: Marc Tormo i Bochaca , 2017\n" +"Language-Team: Catalan (https://www.transifex.com/oca/teams/23907/ca/)\n" +"Language: ca\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Partner form" +msgstr "Empresa de " + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Phone numbers" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "ir.ui.view" +msgstr "ir.ui.view" + +#~ msgid "A new page" +#~ msgstr "Una nova pàgina " diff --git a/base_view_inheritance_extension/i18n/de.po b/base_view_inheritance_extension/i18n/de.po new file mode 100644 index 000000000..0862b29dd --- /dev/null +++ b/base_view_inheritance_extension/i18n/de.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_view_inheritance_extension +# +# Translators: +# Niki Waibel , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-01 02:10+0000\n" +"PO-Revision-Date: 2017-12-01 02:10+0000\n" +"Last-Translator: Niki Waibel , 2017\n" +"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Partner form" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Phone numbers" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "ir.ui.view" +msgstr "ir.ui.view" diff --git a/base_view_inheritance_extension/i18n/es.po b/base_view_inheritance_extension/i18n/es.po new file mode 100644 index 000000000..87cecfad6 --- /dev/null +++ b/base_view_inheritance_extension/i18n/es.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_view_inheritance_extension +# +# Translators: +# Pedro M. Baeza , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-01 02:10+0000\n" +"PO-Revision-Date: 2017-12-01 02:10+0000\n" +"Last-Translator: Pedro M. Baeza , 2017\n" +"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Partner form" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Phone numbers" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "ir.ui.view" +msgstr "ir.ui.view" diff --git a/base_view_inheritance_extension/i18n/hr.po b/base_view_inheritance_extension/i18n/hr.po new file mode 100644 index 000000000..3ded69c2c --- /dev/null +++ b/base_view_inheritance_extension/i18n/hr.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_view_inheritance_extension +# +# Translators: +# Bole , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-03-02 18:40+0000\n" +"PO-Revision-Date: 2018-03-02 18:40+0000\n" +"Last-Translator: Bole , 2018\n" +"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Partner form" +msgstr "Forma partnera" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Phone numbers" +msgstr "Brojevi telefona" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "ir.ui.view" +msgstr "ir.ui.view" diff --git a/base_view_inheritance_extension/i18n/it.po b/base_view_inheritance_extension/i18n/it.po new file mode 100644 index 000000000..c2f0849f2 --- /dev/null +++ b/base_view_inheritance_extension/i18n/it.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_view_inheritance_extension +# +# Translators: +# Paolo Valier , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-06 02:25+0000\n" +"PO-Revision-Date: 2018-01-06 02:25+0000\n" +"Last-Translator: Paolo Valier , 2018\n" +"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Partner form" +msgstr "Form Partner" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Phone numbers" +msgstr "Numeri di telefono" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "ir.ui.view" +msgstr "ir.ui.view" diff --git a/base_view_inheritance_extension/i18n/sl.po b/base_view_inheritance_extension/i18n/sl.po new file mode 100644 index 000000000..864f77e7a --- /dev/null +++ b/base_view_inheritance_extension/i18n/sl.po @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_view_inheritance_extension +# +# Translators: +# Matjaž Mozetič , 2016 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-12-29 03:39+0000\n" +"PO-Revision-Date: 2016-12-29 03:39+0000\n" +"Last-Translator: Matjaž Mozetič , 2016\n" +"Language-Team: Slovenian (https://www.transifex.com/oca/teams/23907/sl/)\n" +"Language: sl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n" +"%100==4 ? 2 : 3);\n" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Partner form" +msgstr "Partnerjev obrazec" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Phone numbers" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "ir.ui.view" +msgstr "" + +#~ msgid "A new page" +#~ msgstr "Nova stran" diff --git a/base_view_inheritance_extension/i18n/tr.po b/base_view_inheritance_extension/i18n/tr.po new file mode 100644 index 000000000..45654394e --- /dev/null +++ b/base_view_inheritance_extension/i18n/tr.po @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_view_inheritance_extension +# +# Translators: +# Ahmet Altinisik , 2016 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-12-29 03:39+0000\n" +"PO-Revision-Date: 2016-12-29 03:39+0000\n" +"Last-Translator: Ahmet Altinisik , 2016\n" +"Language-Team: Turkish (https://www.transifex.com/oca/teams/23907/tr/)\n" +"Language: tr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Partner form" +msgstr "İş ortağı formu" + +#. module: base_view_inheritance_extension +#: model:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Phone numbers" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "ir.ui.view" +msgstr "ir.ui.view" + +#~ msgid "A new page" +#~ msgstr "Yeni bir sayfa" diff --git a/base_view_inheritance_extension/models/__init__.py b/base_view_inheritance_extension/models/__init__.py new file mode 100644 index 000000000..352589cd2 --- /dev/null +++ b/base_view_inheritance_extension/models/__init__.py @@ -0,0 +1,2 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +from . import ir_ui_view diff --git a/base_view_inheritance_extension/models/ir_ui_view.py b/base_view_inheritance_extension/models/ir_ui_view.py new file mode 100644 index 000000000..c95631625 --- /dev/null +++ b/base_view_inheritance_extension/models/ir_ui_view.py @@ -0,0 +1,167 @@ +# Copyright 2016 Therp BV +# Copyright 2018 Tecnativa - Sergio Teruel +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +from lxml import etree +from odoo import api, models, tools +from odoo.tools.safe_eval import safe_eval + + +class UnquoteObject(str): + def __getattr__(self, name): + return UnquoteObject('%s.%s' % (self, name)) + + def __repr__(self): + return self + + def __call__(self, *args, **kwargs): + return UnquoteObject( + '%s(%s)' % ( + self, + ','.join( + [ + UnquoteObject( + a if not isinstance(a, str) + else "'%s'" % a + ) + for a in args + ] + + [ + '%s=%s' % (UnquoteObject(k), v) + for (k, v) in kwargs.items() + ] + ) + ) + ) + + +class UnquoteEvalObjectContext(tools.misc.UnquoteEvalContext): + def __missing__(self, key): + return UnquoteObject(key) + + +class IrUiView(models.Model): + _inherit = 'ir.ui.view' + + @api.model + def apply_inheritance_specs(self, source, specs_tree, inherit_id): + for specs, handled_by in self._iter_inheritance_specs(specs_tree): + source = handled_by(source, specs, inherit_id) + return source + + @api.model + def _iter_inheritance_specs(self, spec): + if spec.tag == 'data': + for child in spec: + for node, handler in self._iter_inheritance_specs(child): + yield node, handler + return + if spec.get('position') == 'attributes': + if all(not c.get('operation') for c in spec): + yield spec, self._get_inheritance_handler(spec) + return + for child in spec: + node = etree.Element(spec.tag, **spec.attrib) + node.insert(0, child) + yield node, self._get_inheritance_handler_attributes( + child + ) + return + yield spec, self._get_inheritance_handler(spec) + + @api.model + def _get_inheritance_handler(self, node): + handler = super(IrUiView, self).apply_inheritance_specs + if hasattr( + self, 'inheritance_handler_%s' % node.tag + ): + handler = getattr( + self, + 'inheritance_handler_%s' % node.tag + ) + return handler + + @api.model + def _get_inheritance_handler_attributes(self, node): + handler = super(IrUiView, self).apply_inheritance_specs + if hasattr( + self, 'inheritance_handler_attributes_%s' % node.get('operation') + ): + handler = getattr( + self, + 'inheritance_handler_attributes_%s' % node.get('operation') + ) + return handler + + @api.model + def inheritance_handler_attributes_python_dict( + self, source, specs, inherit_id + ): + """Implement + <$node position="attributes"> + + $keyvalue + + """ + 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) + return source + + @api.model + def inheritance_handler_xpath(self, source, specs, inherit_id): + if not specs.get('position') == 'move': + return super(IrUiView, self).apply_inheritance_specs( + source, specs, inherit_id + ) + node = self.locate_node(source, specs) + target_node = self.locate_node( + source, etree.Element(specs.tag, expr=specs.get('target')) + ) + target_node.append(node) + return source + + @api.model + def inheritance_handler_attributes_list_add( + self, source, specs, inherit_id + ): + """Implement + <$node position="attributes"> + + $new_value + + """ + node = self.locate_node(source, specs) + for attribute_node in specs: + attribute_name = attribute_node.get('name') + old_value = node.get(attribute_name) or '' + new_value = old_value + ',' + attribute_node.text + node.attrib[attribute_name] = new_value + return source + + @api.model + def inheritance_handler_attributes_list_remove( + self, source, specs, inherit_id + ): + """Implement + <$node position="attributes"> + + $value_to_remove + + """ + node = self.locate_node(source, specs) + for attribute_node in specs: + attribute_name = attribute_node.get('name') + old_values = (node.get(attribute_name) or '').split(',') + remove_values = attribute_node.text.split(',') + new_values = [x for x in old_values if x not in remove_values] + node.attrib[attribute_name] = ','.join( + [_f for _f in new_values if _f]) + return source diff --git a/base_view_inheritance_extension/readme/CONTRIBUTORS.rst b/base_view_inheritance_extension/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..41d2a472c --- /dev/null +++ b/base_view_inheritance_extension/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Holger Brunn +* Ronald Portier +* Sergio Teruel diff --git a/base_view_inheritance_extension/readme/DESCRIPTION.rst b/base_view_inheritance_extension/readme/DESCRIPTION.rst new file mode 100644 index 000000000..0536b6f26 --- /dev/null +++ b/base_view_inheritance_extension/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module was written to make it simple to add custom operators for view +inheritance. diff --git a/base_view_inheritance_extension/readme/ROADMAP.rst b/base_view_inheritance_extension/readme/ROADMAP.rst new file mode 100644 index 000000000..ade040dce --- /dev/null +++ b/base_view_inheritance_extension/readme/ROADMAP.rst @@ -0,0 +1,3 @@ +* add ``$value`` +* support ```` +* support an ``eval`` attribute for our new node types diff --git a/base_view_inheritance_extension/readme/USAGE.rst b/base_view_inheritance_extension/readme/USAGE.rst new file mode 100644 index 000000000..65199fd1e --- /dev/null +++ b/base_view_inheritance_extension/readme/USAGE.rst @@ -0,0 +1,36 @@ +**Change a python dictionary (context for example)** + + +.. code-block:: xml + + + $new_value + + +Note that views are subject to evaluation of xmlids anyways, so if you need +to refer to some xmlid, say ``%(xmlid)s``. + +**Move an element in the view** + +.. code-block:: xml + + + +This can also be used to wrap some element into another, create the target +element first, then move the node youwant to wrap there. + +**Add to values in a list (states for example)** + +.. code-block:: xml + + + $new_value(s) + + +**Remove values from a list (states for example)** + +.. code-block:: xml + + + $remove_value(s) + diff --git a/base_view_inheritance_extension/static/description/icon.png b/base_view_inheritance_extension/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/base_view_inheritance_extension/static/description/icon.png differ diff --git a/base_view_inheritance_extension/static/description/index.html b/base_view_inheritance_extension/static/description/index.html new file mode 100644 index 000000000..3d2599b76 --- /dev/null +++ b/base_view_inheritance_extension/static/description/index.html @@ -0,0 +1,461 @@ + + + + + + +Extended view inheritance + + + +
+

Extended view inheritance

+ + +

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

+ +
+

Usage

+

Change a python dictionary (context for example)

+
+<attribute name="$attribute" operation="python_dict" key="$key">
+    $new_value
+</attribute>
+
+

Note that views are subject to evaluation of xmlids anyways, so if you need +to refer to some xmlid, say %(xmlid)s.

+

Move an element in the view

+
+<xpath expr="$xpath" position="move" target="$targetxpath" />
+
+

This can also be used to wrap some element into another, create the target +element first, then move the node youwant to wrap there.

+

Add to values in a list (states for example)

+
+<attribute name="$attribute" operation="list_add">
+    $new_value(s)
+</attribute>
+
+

Remove values from a list (states for example)

+
+<attribute name="$attribute" operation="list_remove">
+    $remove_value(s)
+</attribute>
+
+
+
+

Known issues / Roadmap

+
    +
  • add <attribute operation="json_dict" key="$key">$value</attribute>
  • +
  • support <xpath expr="$xpath" position="move" target="xpath" target_position="position" />
  • +
  • support an eval attribute for our new node types
  • +
+
+
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Therp BV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

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

+
+
+
+ + diff --git a/base_view_inheritance_extension/tests/__init__.py b/base_view_inheritance_extension/tests/__init__.py new file mode 100644 index 000000000..e19c813a8 --- /dev/null +++ b/base_view_inheritance_extension/tests/__init__.py @@ -0,0 +1,2 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +from . import test_base_view_inheritance_extension 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 new file mode 100644 index 000000000..212a20b5e --- /dev/null +++ b/base_view_inheritance_extension/tests/test_base_view_inheritance_extension.py @@ -0,0 +1,112 @@ +# Copyright 2016 Therp BV +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +from lxml import etree +from odoo.tests.common import TransactionCase + + +class TestBaseViewInheritanceExtension(TransactionCase): + + def test_base_view_inheritance_extension(self): + view_id = self.env.ref('base.view_partner_simple_form').id + fields_view_get = self.env['res.partner'].fields_view_get( + view_id=view_id + ) + view = etree.fromstring(fields_view_get['arch']) + # verify normal attributes work + self.assertEqual(view.xpath('//form')[0].get('string'), 'Partner form') + # verify our extra context key worked + self.assertTrue( + 'default_name' in + view.xpath('//field[@name="parent_id"]')[0].get('context') + ) + self.assertTrue( + "context.get('company_id', context.get('company'))" in + view.xpath('//field[@name="parent_id"]')[0].get('context') + ) + # verify we moved the child_ids field + self.assertEqual( + view.xpath('//field[@name="mobile"]')[0].getparent(), + view.xpath('//page[@name="phone_book"]')[0] + ) + + def test_list_add(self): + view_model = self.env['ir.ui.view'] + inherit_id = self.env.ref('base.view_partner_form').id + source = etree.fromstring( + """\ +
+
+ """ + ) + modified_source = \ + view_model.inheritance_handler_attributes_list_add( + source, specs, inherit_id + ) + button_node = modified_source.xpath('//button[@name="test"]')[0] + self.assertEqual( + button_node.attrib['states'], + 'draft,open,valid' + ) + # extend with list of values + specs = etree.fromstring( + """\ + + """ + ) + modified_source = \ + view_model.inheritance_handler_attributes_list_add( + source, specs, inherit_id + ) + button_node = modified_source.xpath('//button[@name="test"]')[0] + self.assertEqual( + button_node.attrib['states'], + 'draft,open,valid,payable,paid' + ) + + def test_list_remove(self): + view_model = self.env['ir.ui.view'] + inherit_id = self.env.ref('base.view_partner_form').id + source = etree.fromstring( + """\ +
+
+ """ + ) + modified_source = \ + view_model.inheritance_handler_attributes_list_remove( + source, specs, inherit_id + ) + button_node = modified_source.xpath('//button[@name="test"]')[0] + self.assertEqual( + button_node.attrib['states'], + 'draft,valid,paid' + )