diff --git a/base_view_inheritance_extension/README.rst b/base_view_inheritance_extension/README.rst new file mode 100644 index 00000000000..95c8e8e9659 --- /dev/null +++ b/base_view_inheritance_extension/README.rst @@ -0,0 +1,134 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +========================= +Extended view inheritance +========================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:cb2fb0b7f832559d24b4af1f66ac9d92258ed4cb2a2f32b5b1afaa3437f7b9eb + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Mature-brightgreen.png + :target: https://odoo-community.org/page/development-status + :alt: Mature +.. |badge2| image:: https://img.shields.io/badge/license-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/19.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-19-0/server-tools-19-0-base_view_inheritance_extension + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=19.0 + :alt: Try me on Runboat + +|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:: xml + + + + { + "key": "value", + } + + + +Note that views are subject to evaluation of xmlids anyways, so if you +need to refer to some xmlid, say ``%(xmlid)s``. + +**Add text after and/or before than original** + +.. code:: xml + + + $text_before {old_value} $text_after + + +**Add domain with AND/OR join operator (AND if missed) allowing +conditional changes** + +.. code:: xml + + + $domain_to_add + + +Known issues / Roadmap +====================== + +- 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 to smash 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 +- `Tecnativa `__: + + - Sergio Teruel + - Carlos Dauden + +- `Trobz `__: + + - Nhan Tran + +- Iván Todorovich +- Frederic Grall + +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 00000000000..0650744f6bc --- /dev/null +++ b/base_view_inheritance_extension/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_view_inheritance_extension/__manifest__.py b/base_view_inheritance_extension/__manifest__.py new file mode 100644 index 00000000000..d27da32ee46 --- /dev/null +++ b/base_view_inheritance_extension/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2016 Therp BV +# Copyright 2018 Tecnativa - Sergio Teruel +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +{ + "name": "Extended view inheritance", + "version": "19.0.1.0.0", + "development_status": "Mature", + "author": "Therp BV,Odoo Community Association (OCA)", + "license": "LGPL-3", + "category": "Hidden/Dependency", + "summary": "Adds more operators for view inheritance", + "website": "https://github.com/OCA/server-tools", + "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 00000000000..93562cc7a4f --- /dev/null +++ b/base_view_inheritance_extension/demo/ir_ui_view.xml @@ -0,0 +1,29 @@ + + + + res.partner + + + + Partner form + + + + { + "default_email": "info@odoo-community.org", + "default_company_id": allowed_company_ids[0] + } + + + + + 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 00000000000..2b8fb1ec0f5 --- /dev/null +++ b/base_view_inheritance_extension/i18n/base_view_inheritance_extension.pot @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_view_inheritance_extension +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.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_terms:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Partner form" +msgstr "" + +#. module: base_view_inheritance_extension +#: model_terms: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.fields,field_description:base_view_inheritance_extension.field_ir_ui_view__smart_search +msgid "Smart Search" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "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 00000000000..ed7631af066 --- /dev/null +++ b/base_view_inheritance_extension/i18n/ca.po @@ -0,0 +1,45 @@ +# 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_terms: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_terms: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.fields,field_description:base_view_inheritance_extension.field_ir_ui_view__smart_search +msgid "Smart Search" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "View" +msgstr "" + +#~ 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 00000000000..fbe56c6ec8a --- /dev/null +++ b/base_view_inheritance_extension/i18n/de.po @@ -0,0 +1,42 @@ +# 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_terms:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Partner form" +msgstr "" + +#. module: base_view_inheritance_extension +#: model_terms: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.fields,field_description:base_view_inheritance_extension.field_ir_ui_view__smart_search +msgid "Smart Search" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "View" +msgstr "" + +#~ 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 00000000000..63d575e51bc --- /dev/null +++ b/base_view_inheritance_extension/i18n/es.po @@ -0,0 +1,43 @@ +# 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: 2023-09-03 00:14+0000\n" +"Last-Translator: Ivorra78 \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" +"X-Generator: Weblate 4.17\n" + +#. module: base_view_inheritance_extension +#: model_terms:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Partner form" +msgstr "Formulario de socio" + +#. module: base_view_inheritance_extension +#: model_terms:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Phone numbers" +msgstr "Números de teléfono" + +#. module: base_view_inheritance_extension +#: model:ir.model.fields,field_description:base_view_inheritance_extension.field_ir_ui_view__smart_search +msgid "Smart Search" +msgstr "Búsqueda inteligente" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "View" +msgstr "Vista" + +#~ msgid "ir.ui.view" +#~ msgstr "ir.ui.view" diff --git a/base_view_inheritance_extension/i18n/es_AR.po b/base_view_inheritance_extension/i18n/es_AR.po new file mode 100644 index 00000000000..f36856cd13d --- /dev/null +++ b/base_view_inheritance_extension/i18n/es_AR.po @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_view_inheritance_extension +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-06-09 16:09+0000\n" +"Last-Translator: Ignacio Buioli \n" +"Language-Team: none\n" +"Language: es_AR\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" +"X-Generator: Weblate 4.17\n" + +#. module: base_view_inheritance_extension +#: model_terms:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Partner form" +msgstr "Contacto desde" + +#. module: base_view_inheritance_extension +#: model_terms:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Phone numbers" +msgstr "Números de teléfono" + +#. module: base_view_inheritance_extension +#: model:ir.model.fields,field_description:base_view_inheritance_extension.field_ir_ui_view__smart_search +msgid "Smart Search" +msgstr "Búsqueda Inteligente" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "View" +msgstr "Vista" diff --git a/base_view_inheritance_extension/i18n/hr.po b/base_view_inheritance_extension/i18n/hr.po new file mode 100644 index 00000000000..60cbb4746b5 --- /dev/null +++ b/base_view_inheritance_extension/i18n/hr.po @@ -0,0 +1,44 @@ +# 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: 2023-01-04 03:00+0000\n" +"Last-Translator: Bole \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" +"X-Generator: Weblate 4.14.1\n" + +#. module: base_view_inheritance_extension +#: model_terms: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_terms: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.fields,field_description:base_view_inheritance_extension.field_ir_ui_view__smart_search +msgid "Smart Search" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "View" +msgstr "Pogled" + +#~ 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 00000000000..07088e18596 --- /dev/null +++ b/base_view_inheritance_extension/i18n/it.po @@ -0,0 +1,43 @@ +# 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: 2023-09-21 16:40+0000\n" +"Last-Translator: mymage \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" +"X-Generator: Weblate 4.17\n" + +#. module: base_view_inheritance_extension +#: model_terms: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_terms: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.fields,field_description:base_view_inheritance_extension.field_ir_ui_view__smart_search +msgid "Smart Search" +msgstr "Ricerca intelligente" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "View" +msgstr "Vista" + +#~ msgid "ir.ui.view" +#~ msgstr "ir.ui.view" diff --git a/base_view_inheritance_extension/i18n/nl.po b/base_view_inheritance_extension/i18n/nl.po new file mode 100644 index 00000000000..b6e2b796f0b --- /dev/null +++ b/base_view_inheritance_extension/i18n/nl.po @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_view_inheritance_extension +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-11-14 16:02+0000\n" +"Last-Translator: Bosd \n" +"Language-Team: none\n" +"Language: nl\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" +"X-Generator: Weblate 5.10.4\n" + +#. module: base_view_inheritance_extension +#: model_terms:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Partner form" +msgstr "Partner formulier" + +#. module: base_view_inheritance_extension +#: model_terms:ir.ui.view,arch_db:base_view_inheritance_extension.view_partner_simple_form +msgid "Phone numbers" +msgstr "Telefoon nummers" + +#. module: base_view_inheritance_extension +#: model:ir.model.fields,field_description:base_view_inheritance_extension.field_ir_ui_view__smart_search +msgid "Smart Search" +msgstr "Slim zoeken" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "View" +msgstr "Weergave" diff --git a/base_view_inheritance_extension/i18n/sl.po b/base_view_inheritance_extension/i18n/sl.po new file mode 100644 index 00000000000..b8fd545a680 --- /dev/null +++ b/base_view_inheritance_extension/i18n/sl.po @@ -0,0 +1,43 @@ +# 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_terms: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_terms: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.fields,field_description:base_view_inheritance_extension.field_ir_ui_view__smart_search +msgid "Smart Search" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "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 00000000000..bd0e58da97f --- /dev/null +++ b/base_view_inheritance_extension/i18n/tr.po @@ -0,0 +1,45 @@ +# 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_terms: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_terms: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.fields,field_description:base_view_inheritance_extension.field_ir_ui_view__smart_search +msgid "Smart Search" +msgstr "" + +#. module: base_view_inheritance_extension +#: model:ir.model,name:base_view_inheritance_extension.model_ir_ui_view +msgid "View" +msgstr "" + +#~ 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 00000000000..81f52e3bfa6 --- /dev/null +++ b/base_view_inheritance_extension/models/__init__.py @@ -0,0 +1 @@ +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 00000000000..f5aa515ad43 --- /dev/null +++ b/base_view_inheritance_extension/models/ir_ui_view.py @@ -0,0 +1,197 @@ +# Copyright 2016 Therp BV +# Copyright 2018 Tecnativa - Sergio Teruel +# Copyright 2021 Camptocamp SA (https://www.camptocamp.com). +# Copyright 2023 Tecnativa - Carlos Dauden +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +import ast +import re + +from lxml import etree + +from odoo import api, models +from odoo.fields import Domain + + +def ast_dict_update(source, update): + """Perform a dict `update` on an ast.Dict + + Behaves similar to :meth:`dict.update`, but on ast.Dict instead. + Only compares string-like ast.Dict keys (ast.Str or ast.Constant). + + :returns: The updated ast.Dict + :rtype: ast.Dict + """ + if not isinstance(source, ast.Dict): + raise TypeError("`source` must be an AST dict") + if not isinstance(update, ast.Dict): + raise TypeError("`update` must be an AST dict") + + def ast_key_eq(k1, k2): + if type(k1) is not type(k2): + return False + elif isinstance(k1, ast.Constant): + return k1.value == k2.value + + toadd_uidx = [] + for uidx, ukey in enumerate(update.keys): + found = False + for sidx, skey in enumerate(source.keys): + if ast_key_eq(ukey, skey): + source.values[sidx] = update.values[uidx] + found = True + break + if not found: + toadd_uidx.append(uidx) + for uidx in toadd_uidx: + source.keys.append(update.keys[uidx]) + source.values.append(update.values[uidx]) + return source + + +class IrUiView(models.Model): + _inherit = "ir.ui.view" + + @api.model + def apply_inheritance_specs(self, source, specs_tree, pre_locate=lambda s: True): + for specs, handled_by in self._iter_inheritance_specs(specs_tree): + pre_locate(specs) + source = handled_by(source, specs) + 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().apply_inheritance_specs + if hasattr(self, f"inheritance_handler_{node.tag}"): + handler = getattr(self, f"inheritance_handler_{node.tag}") + return handler + + @api.model + def _get_inheritance_handler_attributes(self, node): + handler = super().apply_inheritance_specs + if hasattr(self, f"_inheritance_handler_attributes_{node.get('operation')}"): + handler = getattr( + self, f"_inheritance_handler_attributes_{node.get('operation')}" + ) + return handler + + @api.model + def _inheritance_handler_attributes_update(self, source, specs): + """Implement dict `update` operation on the attribute node. + + .. code-block:: xml + + + + { + "key": "value", + } + + + """ + node = self.locate_node(source, specs) + for spec in specs: + attr_name = spec.get("name") + # Parse ast from both node and spec + node_attr = (node.get(attr_name) or "{}").strip() + source_ast = ast.parse(node_attr, mode="eval").body + update_ast = ast.parse(spec.text.strip(), mode="eval").body + if not isinstance(source_ast, ast.Dict): + raise TypeError(f"Attribute `{attr_name}` is not a dict") + if not isinstance(update_ast, ast.Dict): + raise TypeError(f"Operation for attribute `{attr_name}` is not a dict") + # Update node ast dict + source_ast = ast_dict_update(source_ast, update_ast) + # Dump the ast back to source + node.attrib[attr_name] = ast.unparse(source_ast).strip() + return source + + @api.model + def _inheritance_handler_attributes_text_add(self, source, specs): + """Implement + <$node position="attributes"> + + $text_before {old_value} $text_after + + """ + node = self.locate_node(source, specs) + for attribute_node in specs: + attribute_name = attribute_node.get("name") + old_value = node.get(attribute_name) or "" + node.attrib[attribute_name] = attribute_node.text.format( + old_value=old_value + ) + return source + + @api.model + def _inheritance_handler_attributes_domain_add(self, source, specs): + """Implement + <$node position="attributes"> + + $domain_to_add + + """ + node = self.locate_node(source, specs) + for attribute_node in specs: + attribute_name = attribute_node.get("name") + condition = attribute_node.get("condition") + join_operator = attribute_node.get("join_operator") or "AND" + old_value = node.get(attribute_name) or "" + if old_value: + old_domain = ast.literal_eval( + self._var2str_domain_text(old_value.strip()) + ) + new_domain = ast.literal_eval( + self._var2str_domain_text(attribute_node.text.strip()) + ) + if join_operator == "OR": + new_value = str(Domain.OR([old_domain, new_domain])) + else: + new_value = str(Domain.AND([old_domain, new_domain])) + new_value = self._str2var_domain_text(new_value) + old_value = "".join(old_value.splitlines()) + else: + # We must ensure that the domain definition has not line breaks because + # in update mode the domain cause an invalid syntax error + new_value = attribute_node.text.strip() + if condition: + new_value = f"{condition} and {new_value} or {old_value or []}" + node.attrib[attribute_name] = new_value + return source + + @api.model + def _var2str_domain_text(self, domain_str): + """Replaces var names with str names to allow eval without defined vars""" + # Replace fields in 2 steps because 1 step returns "parent_sufix"."var_sufix" + regex_parent = re.compile(r"parent\.(\b\w+\b)") + domain_str = re.sub( + regex_parent, r"'parent.\1_is_a_var_to_replace'", domain_str + ) + regex = re.compile(r"(?\> +- Ronald Portier \<\> +- [Tecnativa](https://www.tecnativa.com): + - Sergio Teruel + - Carlos Dauden +- [Trobz](https://www.trobz.com): + - Nhan Tran \<\> +- Iván Todorovich \<\> +- Frederic Grall \<> diff --git a/base_view_inheritance_extension/readme/DESCRIPTION.md b/base_view_inheritance_extension/readme/DESCRIPTION.md new file mode 100644 index 00000000000..4fc9dc0a49d --- /dev/null +++ b/base_view_inheritance_extension/readme/DESCRIPTION.md @@ -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.md b/base_view_inheritance_extension/readme/ROADMAP.md new file mode 100644 index 00000000000..f2dc1c6a7b3 --- /dev/null +++ b/base_view_inheritance_extension/readme/ROADMAP.md @@ -0,0 +1 @@ +- Support an `eval` attribute for our new node types. diff --git a/base_view_inheritance_extension/readme/USAGE.md b/base_view_inheritance_extension/readme/USAGE.md new file mode 100644 index 00000000000..e4bda1aa927 --- /dev/null +++ b/base_view_inheritance_extension/readme/USAGE.md @@ -0,0 +1,32 @@ +**Change a python dictionary (context for example)** + +``` xml + + + { + "key": "value", + } + + +``` + +Note that views are subject to evaluation of xmlids anyways, so if you +need to refer to some xmlid, say `%(xmlid)s`. + +**Add text after and/or before than original** + +``` xml + + $text_before {old_value} $text_after + +``` + +**Add domain with AND/OR join operator (AND if missed) allowing +conditional changes** + +``` xml + + $domain_to_add + +``` 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 00000000000..3a0328b516c 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 00000000000..1f046f10423 --- /dev/null +++ b/base_view_inheritance_extension/static/description/index.html @@ -0,0 +1,479 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Extended view inheritance

+ +

Mature License: LGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

+

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)

+
+<field position="attributes">
+    <attribute name="context" operation="update">
+        {
+            "key": "value",
+        }
+    </attribute>
+</field>
+
+

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

+

Add text after and/or before than original

+
+<attribute name="$attribute" operation="text_add">
+    $text_before {old_value} $text_after
+</attribute>
+
+

Add domain with AND/OR join operator (AND if missed) allowing +conditional changes

+
+<attribute name="$attribute" operation="domain_add"
+           condition="$field_condition" join_operator="OR">
+    $domain_to_add
+</attribute>
+
+
+
+

Known issues / Roadmap

+
    +
  • 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 to smash 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 00000000000..261fddfad36 --- /dev/null +++ b/base_view_inheritance_extension/tests/__init__.py @@ -0,0 +1 @@ +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 00000000000..c4b76132f3e --- /dev/null +++ b/base_view_inheritance_extension/tests/test_base_view_inheritance_extension.py @@ -0,0 +1,224 @@ +# Copyright 2016 Therp BV +# Copyright 2021 Camptocamp SA (https://www.camptocamp.com). +# @author Iván Todorovich +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from lxml import etree + +from odoo.tests.common import TransactionCase + + +class TestBaseViewInheritanceExtension(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.maxDiff = None + cls.view = cls.env["ir.ui.view"].create( + { + "name": "Test Partner Simple Form Override", + "type": "form", + "model": "res.partner", + "inherit_id": cls.env.ref("base.view_partner_simple_form").id, + "arch": """ + + + Partner form + + + + + { + "default_email": "info@odoo-community.org", + "default_company_id": allowed_company_ids[0] + } + + + + """, + } + ) + + def test_base_view_inheritance_extension(self): + arch, _ = self.env["res.partner"]._get_view(view_id=self.view.id) + # Verify normal attributes work + self.assertEqual(arch.xpath("//form")[0].get("string"), "Partner form") + # Verify our extra context key worked + self.assertTrue( + "'default_email': 'info@odoo-community.org'" + in arch.xpath('//field[@name="parent_id"]')[0].get("context") + ) + self.assertTrue( + "'default_company_id': allowed_company_ids[0]" + in arch.xpath('//field[@name="parent_id"]')[0].get("context") + ) + + def test_update_context_default(self): + source = etree.fromstring( + """ +
+ + + """ + ) + specs = etree.fromstring( + """ + + + {"default_company_id": company_id} + + + """ + ) + res = self.env["ir.ui.view"].apply_inheritance_specs(source, specs) + self.assertEqual( + res.xpath('//field[@name="account_move_id"]')[0].attrib["context"], + "{'default_journal_id': journal_id, 'default_company_id': company_id}", + ) + + def test_update_context_complex(self): + source = etree.fromstring( + """ +
+ + + """ + ) + specs = etree.fromstring( + """ + + + { + "default_product_id": product_id, + "default_cost_center_id": ( + context.get("handle_mrp_cost") and cost_center_id or False + ), + } + + + """ + ) + res = self.env["ir.ui.view"].apply_inheritance_specs(source, specs) + expected_items = [ + "'default_type': context.get('default_type')", + "'journal_id': journal_id", + "'default_partner_id': commercial_partner_id", + ( + "'default_currency_id': " + "currency_id != company_currency_id and currency_id or False" + ), + "'default_name': 'The company name'", + "'default_product_id': product_id", + ( + "'default_cost_center_id': " + "context.get('handle_mrp_cost') and cost_center_id or False" + ), + ] + self.assertEqual( + res.xpath('//field[@name="invoice_line_ids"]')[0].attrib["context"], + "{%s}" % ", ".join(expected_items), # noqa: UP031 + ) + + def test_text_add_operation(self): + source = etree.fromstring( + """ +
+ + + """ + ) + + specs = etree.fromstring( + """ + + {old_value} Customer + + """ + ) + + res = self.env["ir.ui.view"].apply_inheritance_specs(source, specs) + self.assertEqual( + res.xpath('//field[@name="customer_id"]')[0].attrib["string"], + "Client Customer", + ) + + def test_update_operation_not_a_dict(self): + """We should get an error if we try to update a dict with a non-dict spec""" + source = etree.fromstring( + """ +
+ + + """ + ) + specs = etree.fromstring( + """ + + + ["not", "a", "dict"] + + + """ + ) + with self.assertRaisesRegex( + TypeError, "Operation for attribute `context` is not a dict" + ): + self.env["ir.ui.view"].apply_inheritance_specs(source, specs) + + def test_domain_add_operation(self): + source = etree.fromstring( + """ +
+ + + """ + ) + specs = etree.fromstring( + """ + + + [('state', '!=', 'draft')] + + + """ + ) + res = self.env["ir.ui.view"].apply_inheritance_specs(source, specs) + self.assertEqual( + res.xpath('//field[@name="child_ids"]')[0].attrib["domain"], + "['&', ('state', '=', 'confirm'), ('state', '!=', 'draft')]", + ) + + def test_update_source_not_a_dict(self): + """We should get an error if we try to update a non-dict attribute""" + source = etree.fromstring( + """ +
+ + + """ + ) + specs = etree.fromstring( + """ + + + { + "required": [('state', '!=', 'draft')], + } + + + """ + ) + with self.assertRaisesRegex(TypeError, "Attribute `domain` is not a dict"): + self.env["ir.ui.view"].apply_inheritance_specs(source, specs)