diff --git a/web_widget_open_tab/README.rst b/web_widget_open_tab/README.rst new file mode 100644 index 000000000000..8391be55e2a0 --- /dev/null +++ b/web_widget_open_tab/README.rst @@ -0,0 +1,106 @@ +====================== +Widget Open on new Tab +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:a14f7a08311efe9efc5c2e59a089a3adfe9f4a41cafd1c7c4c8bf9aac5db6706 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/17.0/web_widget_open_tab + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-17-0/web-17-0-web_widget_open_tab + :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/web&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This addon introduces a new widget. When added to a field in a tree +view, the field appears as a button which opens the record in a new tab. +When clicking on the line (but not on the button), the record is opened +in the same window (as in native Odoo). + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Edit the tree view and add the widget as the first field, usually, we +should use: .. code-block:: xml + + + +You can open the record in a new tab when clicking with the mouse wheel +on the external link icon. On a usual click the record will be opened +without changes (keeping the breadcrumbs). + +You can also add open-tab field in tree views by selecting "Add Open Tab +Field" field in the ir.model record. When you do this, the open-tab +field is added right after the name field in the tree if the field +exists, otherwise at the beginning of the tree. + +Known issues / Roadmap +====================== + +- Add many2one fields support. + +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 +------- + +* Creu Blanca + +Contributors +------------ + +- Enric Tobella +- Raf Ven +- Dhara Solanki +- `Quartile `__: + + - Aung Ko Ko Lin + +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/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_widget_open_tab/__init__.py b/web_widget_open_tab/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/web_widget_open_tab/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/web_widget_open_tab/__manifest__.py b/web_widget_open_tab/__manifest__.py new file mode 100644 index 000000000000..280d50704ecc --- /dev/null +++ b/web_widget_open_tab/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2019-2020 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Widget Open on new Tab", + "summary": """ + Allow to open record from trees on new tab from tree views""", + "version": "17.0.1.0.0", + "license": "AGPL-3", + "author": "Creu Blanca,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", + "depends": ["web"], + "demo": ["demo/res_users_view.xml"], + "data": [ + "views/ir_model_views.xml", + ], + "assets": { + "web.assets_backend": [ + "web_widget_open_tab/static/src/xml/open_tab_widget.xml", + "web_widget_open_tab/static/src/js/open_tab_widget.esm.js", + ], + }, +} diff --git a/web_widget_open_tab/demo/res_users_view.xml b/web_widget_open_tab/demo/res_users_view.xml new file mode 100644 index 000000000000..3d701f0a951e --- /dev/null +++ b/web_widget_open_tab/demo/res_users_view.xml @@ -0,0 +1,12 @@ + + + + res.users + + + + + + + + diff --git a/web_widget_open_tab/i18n/ca.po b/web_widget_open_tab/i18n/ca.po new file mode 100644 index 000000000000..f151dac10109 --- /dev/null +++ b/web_widget_open_tab/i18n/ca.po @@ -0,0 +1,59 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_open_tab +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-02-17 13:45+0000\n" +"Last-Translator: claudiagn \n" +"Language-Team: none\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" +"X-Generator: Weblate 4.3.2\n" + +#. module: web_widget_open_tab +#: model:ir.model.fields,field_description:web_widget_open_tab.field_ir_model__add_open_tab_field +msgid "Add Open Tab Field" +msgstr "" + +#. module: web_widget_open_tab +#: model:ir.model.fields,help:web_widget_open_tab.field_ir_model__add_open_tab_field +msgid "Adds open-tab field in list views." +msgstr "" + +#. module: web_widget_open_tab +#: model:ir.model,name:web_widget_open_tab.model_base +msgid "Base" +msgstr "" + +#. module: web_widget_open_tab +#. odoo-javascript +#: code:addons/web_widget_open_tab/static/src/js/open_tab_widget.esm.js:0 +#, python-format +msgid "Click to open on new tab" +msgstr "" + +#. module: web_widget_open_tab +#: model:ir.model,name:web_widget_open_tab.model_ir_model +msgid "Models" +msgstr "" + +#. module: web_widget_open_tab +#. odoo-javascript +#: code:addons/web_widget_open_tab/static/src/js/open_tab_widget.esm.js:0 +#, python-format +msgid "Open Tab" +msgstr "" + +#, python-format +#~ msgid "Click in order to open on new tab" +#~ msgstr "Feu clic per obrir la pestanya nova" + +#, python-format +#~ msgid "Widget" +#~ msgstr "Widget" diff --git a/web_widget_open_tab/i18n/de.po b/web_widget_open_tab/i18n/de.po new file mode 100644 index 000000000000..406ca92f9fa6 --- /dev/null +++ b/web_widget_open_tab/i18n/de.po @@ -0,0 +1,59 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_open_tab +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-10-13 20:46+0000\n" +"Last-Translator: Corneliuus \n" +"Language-Team: none\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" +"X-Generator: Weblate 4.3.2\n" + +#. module: web_widget_open_tab +#: model:ir.model.fields,field_description:web_widget_open_tab.field_ir_model__add_open_tab_field +msgid "Add Open Tab Field" +msgstr "" + +#. module: web_widget_open_tab +#: model:ir.model.fields,help:web_widget_open_tab.field_ir_model__add_open_tab_field +msgid "Adds open-tab field in list views." +msgstr "" + +#. module: web_widget_open_tab +#: model:ir.model,name:web_widget_open_tab.model_base +msgid "Base" +msgstr "" + +#. module: web_widget_open_tab +#. odoo-javascript +#: code:addons/web_widget_open_tab/static/src/js/open_tab_widget.esm.js:0 +#, python-format +msgid "Click to open on new tab" +msgstr "" + +#. module: web_widget_open_tab +#: model:ir.model,name:web_widget_open_tab.model_ir_model +msgid "Models" +msgstr "" + +#. module: web_widget_open_tab +#. odoo-javascript +#: code:addons/web_widget_open_tab/static/src/js/open_tab_widget.esm.js:0 +#, python-format +msgid "Open Tab" +msgstr "" + +#, python-format +#~ msgid "Click in order to open on new tab" +#~ msgstr "Anklicken, um in einem neuen Tab zu öffnen" + +#, python-format +#~ msgid "Widget" +#~ msgstr "Widget" diff --git a/web_widget_open_tab/i18n/es.po b/web_widget_open_tab/i18n/es.po new file mode 100644 index 000000000000..7ae8024a5339 --- /dev/null +++ b/web_widget_open_tab/i18n/es.po @@ -0,0 +1,59 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_open_tab +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-09-20 17:50+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\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: web_widget_open_tab +#: model:ir.model.fields,field_description:web_widget_open_tab.field_ir_model__add_open_tab_field +msgid "Add Open Tab Field" +msgstr "Añadir campo de pestaña abierta" + +#. module: web_widget_open_tab +#: model:ir.model.fields,help:web_widget_open_tab.field_ir_model__add_open_tab_field +msgid "Adds open-tab field in list views." +msgstr "Añade un campo de pestaña abierta en las vistas de lista." + +#. module: web_widget_open_tab +#: model:ir.model,name:web_widget_open_tab.model_base +msgid "Base" +msgstr "Base" + +#. module: web_widget_open_tab +#. odoo-javascript +#: code:addons/web_widget_open_tab/static/src/js/open_tab_widget.esm.js:0 +#, python-format +msgid "Click to open on new tab" +msgstr "Haga clic para abrir en una nueva pestaña" + +#. module: web_widget_open_tab +#: model:ir.model,name:web_widget_open_tab.model_ir_model +msgid "Models" +msgstr "Modelos" + +#. module: web_widget_open_tab +#. odoo-javascript +#: code:addons/web_widget_open_tab/static/src/js/open_tab_widget.esm.js:0 +#, python-format +msgid "Open Tab" +msgstr "Abrir pestaña" + +#, python-format +#~ msgid "Click in order to open on new tab" +#~ msgstr "Clica para poder abrir una nueva pestaña" + +#, python-format +#~ msgid "Widget" +#~ msgstr "Widget" diff --git a/web_widget_open_tab/i18n/ja.po b/web_widget_open_tab/i18n/ja.po new file mode 100644 index 000000000000..0608035d3106 --- /dev/null +++ b/web_widget_open_tab/i18n/ja.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_open_tab +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-05-27 08:24+0000\n" +"PO-Revision-Date: 2023-05-27 08:24+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: web_widget_open_tab +#: model:ir.model.fields,field_description:web_widget_open_tab.field_ir_model__add_open_tab_field +msgid "Add Open Tab Field" +msgstr "別タブ表示ボタン追加" + +#. module: web_widget_open_tab +#: model:ir.model.fields,help:web_widget_open_tab.field_ir_model__add_open_tab_field +msgid "Adds open-tab field in list views." +msgstr "リストビューに別タブ表示ボタンを追加。" + +#. module: web_widget_open_tab +#: model:ir.model,name:web_widget_open_tab.model_base +msgid "Base" +msgstr "ベース" + +#. module: web_widget_open_tab +#. odoo-javascript +#: code:addons/web_widget_open_tab/static/src/js/open_tab_widget.esm.js:0 +#, python-format +msgid "Click to open on new tab" +msgstr "クリックして別タブを開く" + +#. module: web_widget_open_tab +#: model:ir.model,name:web_widget_open_tab.model_ir_model +msgid "Models" +msgstr "モデル" + +#. module: web_widget_open_tab +#. odoo-javascript +#: code:addons/web_widget_open_tab/static/src/js/open_tab_widget.esm.js:0 +#, python-format +msgid "Open Tab" +msgstr "別タブを開く" diff --git a/web_widget_open_tab/i18n/pt_BR.po b/web_widget_open_tab/i18n/pt_BR.po new file mode 100644 index 000000000000..7929867698c9 --- /dev/null +++ b/web_widget_open_tab/i18n/pt_BR.po @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_open_tab +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: pt_BR\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: web_widget_open_tab +#: model:ir.model.fields,field_description:web_widget_open_tab.field_ir_model__add_open_tab_field +msgid "Add Open Tab Field" +msgstr "" + +#. module: web_widget_open_tab +#: model:ir.model.fields,help:web_widget_open_tab.field_ir_model__add_open_tab_field +msgid "Adds open-tab field in list views." +msgstr "" + +#. module: web_widget_open_tab +#: model:ir.model,name:web_widget_open_tab.model_base +msgid "Base" +msgstr "" + +#. module: web_widget_open_tab +#. odoo-javascript +#: code:addons/web_widget_open_tab/static/src/js/open_tab_widget.esm.js:0 +#, python-format +msgid "Click to open on new tab" +msgstr "" + +#. module: web_widget_open_tab +#: model:ir.model,name:web_widget_open_tab.model_ir_model +msgid "Models" +msgstr "" + +#. module: web_widget_open_tab +#. odoo-javascript +#: code:addons/web_widget_open_tab/static/src/js/open_tab_widget.esm.js:0 +#, python-format +msgid "Open Tab" +msgstr "" diff --git a/web_widget_open_tab/i18n/web_widget_open_tab.pot b/web_widget_open_tab/i18n/web_widget_open_tab.pot new file mode 100644 index 000000000000..886fd78c1b49 --- /dev/null +++ b/web_widget_open_tab/i18n/web_widget_open_tab.pot @@ -0,0 +1,48 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_open_tab +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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: web_widget_open_tab +#: model:ir.model.fields,field_description:web_widget_open_tab.field_ir_model__add_open_tab_field +msgid "Add Open Tab Field" +msgstr "" + +#. module: web_widget_open_tab +#: model:ir.model.fields,help:web_widget_open_tab.field_ir_model__add_open_tab_field +msgid "Adds open-tab field in list views." +msgstr "" + +#. module: web_widget_open_tab +#: model:ir.model,name:web_widget_open_tab.model_base +msgid "Base" +msgstr "" + +#. module: web_widget_open_tab +#. odoo-javascript +#: code:addons/web_widget_open_tab/static/src/js/open_tab_widget.esm.js:0 +#, python-format +msgid "Click to open on new tab" +msgstr "" + +#. module: web_widget_open_tab +#: model:ir.model,name:web_widget_open_tab.model_ir_model +msgid "Models" +msgstr "" + +#. module: web_widget_open_tab +#. odoo-javascript +#: code:addons/web_widget_open_tab/static/src/js/open_tab_widget.esm.js:0 +#, python-format +msgid "Open Tab" +msgstr "" diff --git a/web_widget_open_tab/models/__init__.py b/web_widget_open_tab/models/__init__.py new file mode 100644 index 000000000000..9368777a039d --- /dev/null +++ b/web_widget_open_tab/models/__init__.py @@ -0,0 +1,2 @@ +from . import ir_model +from . import ir_ui_view diff --git a/web_widget_open_tab/models/ir_model.py b/web_widget_open_tab/models/ir_model.py new file mode 100644 index 000000000000..667576758d73 --- /dev/null +++ b/web_widget_open_tab/models/ir_model.py @@ -0,0 +1,10 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class IrModel(models.Model): + _inherit = "ir.model" + + add_open_tab_field = fields.Boolean(help="Adds open-tab field in list views.") diff --git a/web_widget_open_tab/models/ir_ui_view.py b/web_widget_open_tab/models/ir_ui_view.py new file mode 100644 index 000000000000..4004fe8dd6d5 --- /dev/null +++ b/web_widget_open_tab/models/ir_ui_view.py @@ -0,0 +1,25 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from lxml import etree + +from odoo import api, models + + +class Base(models.AbstractModel): + _inherit = "base" + + @api.model + def _get_view(self, view_id=None, view_type="form", **options): + arch, view = super()._get_view(view_id, view_type, **options) + model = self.env["ir.model"]._get(self._name) + if view_type == "tree" and model.add_open_tab_field: + id_elem = """""" + id_elem = etree.fromstring(id_elem) + tree = arch.xpath("//tree")[0] + name_field = tree.xpath('./field[@name="name"]') + if name_field: + tree.insert(name_field[0].getparent().index(name_field[0]) + 1, id_elem) + else: + tree.insert(0, id_elem) + return arch, view diff --git a/web_widget_open_tab/pyproject.toml b/web_widget_open_tab/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/web_widget_open_tab/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/web_widget_open_tab/readme/CONTRIBUTORS.md b/web_widget_open_tab/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..dfb8714e2d47 --- /dev/null +++ b/web_widget_open_tab/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- Enric Tobella \<\> +- Raf Ven \<\> +- Dhara Solanki \<\> +- [Quartile](https://www.quartile.co): + - Aung Ko Ko Lin diff --git a/web_widget_open_tab/readme/DESCRIPTION.md b/web_widget_open_tab/readme/DESCRIPTION.md new file mode 100644 index 000000000000..21e03d94d779 --- /dev/null +++ b/web_widget_open_tab/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +This addon introduces a new widget. When added to a field in a tree +view, the field appears as a button which opens the record in a new tab. +When clicking on the line (but not on the button), the record is opened +in the same window (as in native Odoo). diff --git a/web_widget_open_tab/readme/ROADMAP.md b/web_widget_open_tab/readme/ROADMAP.md new file mode 100644 index 000000000000..85444f1b265e --- /dev/null +++ b/web_widget_open_tab/readme/ROADMAP.md @@ -0,0 +1 @@ +- Add many2one fields support. diff --git a/web_widget_open_tab/readme/USAGE.md b/web_widget_open_tab/readme/USAGE.md new file mode 100644 index 000000000000..d075c1498269 --- /dev/null +++ b/web_widget_open_tab/readme/USAGE.md @@ -0,0 +1,13 @@ +Edit the tree view and add the widget as the first field, usually, we +should use: .. code-block:: xml + +> \ + +You can open the record in a new tab when clicking with the mouse wheel +on the external link icon. On a usual click the record will be opened +without changes (keeping the breadcrumbs). + +You can also add open-tab field in tree views by selecting "Add Open Tab +Field" field in the ir.model record. When you do this, the open-tab +field is added right after the name field in the tree if the field +exists, otherwise at the beginning of the tree. diff --git a/web_widget_open_tab/static/description/icon.png b/web_widget_open_tab/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/web_widget_open_tab/static/description/icon.png differ diff --git a/web_widget_open_tab/static/description/index.html b/web_widget_open_tab/static/description/index.html new file mode 100644 index 000000000000..01dcbde22eec --- /dev/null +++ b/web_widget_open_tab/static/description/index.html @@ -0,0 +1,452 @@ + + + + + + +Widget Open on new Tab + + + +
+

Widget Open on new Tab

+ + +

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

This addon introduces a new widget. When added to a field in a tree +view, the field appears as a button which opens the record in a new tab. +When clicking on the line (but not on the button), the record is opened +in the same window (as in native Odoo).

+

Table of contents

+ +
+

Usage

+

Edit the tree view and add the widget as the first field, usually, we +should use: .. code-block:: xml

+
+<field name=”id” widget=”open_tab”/>
+

You can open the record in a new tab when clicking with the mouse wheel +on the external link icon. On a usual click the record will be opened +without changes (keeping the breadcrumbs).

+

You can also add open-tab field in tree views by selecting “Add Open Tab +Field” field in the ir.model record. When you do this, the open-tab +field is added right after the name field in the tree if the field +exists, otherwise at the beginning of the tree.

+
+
+

Known issues / Roadmap

+
    +
  • Add many2one fields support.
  • +
+
+
+

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

+
    +
  • Creu Blanca
  • +
+
+
+

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/web project on GitHub.

+

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

+
+
+
+ + diff --git a/web_widget_open_tab/static/src/js/open_tab_widget.esm.js b/web_widget_open_tab/static/src/js/open_tab_widget.esm.js new file mode 100644 index 000000000000..d306f8c0634d --- /dev/null +++ b/web_widget_open_tab/static/src/js/open_tab_widget.esm.js @@ -0,0 +1,46 @@ +/** @odoo-module */ + +import {Component} from "@odoo/owl"; +import {_t} from "@web/core/l10n/translation"; +import {registry} from "@web/core/registry"; +import {standardFieldProps} from "@web/views/fields/standard_field_props"; + +export class OpenTabWidget extends Component { + openNewTab(ev) { + ev.stopPropagation(); + } + _getReference() { + var url = window.location.href; + var searchParams = new URLSearchParams(url.split("#")[1]); + searchParams.set("view_type", "form"); + searchParams.set("id", this.props.record.data.id); + if ( + !searchParams.has("model") || + searchParams.get("model") !== this.props.record.resModel + ) { + searchParams.set("model", this.props.record.resModel); + searchParams.delete("action"); + } + return url.split("#")[0] + "#" + searchParams.toString(); + } + loadAttrs(ev) { + $(ev.target).tooltip(); + } +} + +OpenTabWidget.template = "web_widget_open_tab.openTab"; +OpenTabWidget.props = { + ...standardFieldProps, + title: {type: String, optional: true}, +}; + +export const openTabWidget = { + component: OpenTabWidget, + displayName: _t("Open Tab"), + supportedTypes: ["integer"], + extractProps: () => ({ + title: _t("Click to open on new tab"), + }), +}; + +registry.category("fields").add("open_tab", openTabWidget); diff --git a/web_widget_open_tab/static/src/xml/open_tab_widget.xml b/web_widget_open_tab/static/src/xml/open_tab_widget.xml new file mode 100644 index 000000000000..714b8559cb2a --- /dev/null +++ b/web_widget_open_tab/static/src/xml/open_tab_widget.xml @@ -0,0 +1,14 @@ + + diff --git a/web_widget_open_tab/tests/__init__.py b/web_widget_open_tab/tests/__init__.py new file mode 100644 index 000000000000..6c9812dc2f73 --- /dev/null +++ b/web_widget_open_tab/tests/__init__.py @@ -0,0 +1 @@ +from . import test_main diff --git a/web_widget_open_tab/tests/test_main.py b/web_widget_open_tab/tests/test_main.py new file mode 100644 index 000000000000..393b3791a4ea --- /dev/null +++ b/web_widget_open_tab/tests/test_main.py @@ -0,0 +1,21 @@ +from odoo.tests import common + + +class Test(common.TransactionCase): + def test_add_open_tab_field(self): + self.env["ir.model"]._get("res.company").add_open_tab_field = True + arch, view = self.env["res.company"]._get_view(view_id=None, view_type="tree") + found = arch.xpath("//field[@widget='open_tab']") + self.assertEqual(len(found), 1) + + def test_no_add_open_tab_field(self): + self.env["ir.model"]._get("res.company").add_open_tab_field = False + arch, view = self.env["res.company"]._get_view(view_id=None, view_type="tree") + found = arch.xpath("//field[@widget='open_tab']") + self.assertFalse(found) + + def test_add_open_tab_field_no_name_field(self): + self.env["ir.model"]._get("res.groups").add_open_tab_field = True + arch, view = self.env["res.groups"]._get_view(view_id=None, view_type="tree") + found = arch.xpath("//field[@widget='open_tab']") + self.assertEqual(len(found), 1) diff --git a/web_widget_open_tab/views/ir_model_views.xml b/web_widget_open_tab/views/ir_model_views.xml new file mode 100644 index 000000000000..78acc1178e97 --- /dev/null +++ b/web_widget_open_tab/views/ir_model_views.xml @@ -0,0 +1,13 @@ + + + + ir.model.view.form + ir.model + + + + + + + +