diff --git a/web_widget_open_tab/README.rst b/web_widget_open_tab/README.rst index d6cd282f4..30a2d282d 100644 --- a/web_widget_open_tab/README.rst +++ b/web_widget_open_tab/README.rst @@ -48,6 +48,10 @@ Edit the tree view and add the widget as the first field, usually, we should use 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. + Bug Tracker =========== @@ -71,6 +75,9 @@ Contributors * Enric Tobella * Raf Ven +* `Quartile `__: + + * Aung Ko Ko Lin Maintainers ~~~~~~~~~~~ diff --git a/web_widget_open_tab/__init__.py b/web_widget_open_tab/__init__.py index e69de29bb..0650744f6 100644 --- a/web_widget_open_tab/__init__.py +++ 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 index 3f359385d..3141c71f6 100644 --- a/web_widget_open_tab/__manifest__.py +++ b/web_widget_open_tab/__manifest__.py @@ -11,6 +11,9 @@ "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/js/widget.js"], }, diff --git a/web_widget_open_tab/models/__init__.py b/web_widget_open_tab/models/__init__.py new file mode 100644 index 000000000..9368777a0 --- /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 000000000..667576758 --- /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 000000000..1ae7143e2 --- /dev/null +++ b/web_widget_open_tab/models/ir_ui_view.py @@ -0,0 +1,32 @@ +# 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 fields_view_get( + self, view_id=None, view_type="form", toolbar=False, submenu=False + ): + res = super(Base, self).fields_view_get( + view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu + ) + arch = etree.fromstring(res["arch"]) + 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 = arch.xpath("//tree")[0] + tree.insert(name_field[0].getparent().index(name_field[0]) + 1, id_elem) + else: + tree.insert(0, id_elem) + res["arch"] = etree.tostring(arch) + return res diff --git a/web_widget_open_tab/readme/CONTRIBUTORS.rst b/web_widget_open_tab/readme/CONTRIBUTORS.rst index 271468bb5..f107fa371 100644 --- a/web_widget_open_tab/readme/CONTRIBUTORS.rst +++ b/web_widget_open_tab/readme/CONTRIBUTORS.rst @@ -1,2 +1,5 @@ * Enric Tobella * Raf Ven +* `Quartile `__: + + * Aung Ko Ko Lin diff --git a/web_widget_open_tab/readme/USAGE.rst b/web_widget_open_tab/readme/USAGE.rst index a47bb4fd0..3e4bb3c66 100644 --- a/web_widget_open_tab/readme/USAGE.rst +++ b/web_widget_open_tab/readme/USAGE.rst @@ -5,3 +5,7 @@ Edit the tree view and add the widget as the first field, usually, we should use 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/index.html b/web_widget_open_tab/static/description/index.html index 4fe8fa138..d131fc459 100644 --- a/web_widget_open_tab/static/description/index.html +++ b/web_widget_open_tab/static/description/index.html @@ -394,6 +394,9 @@ When clicking on the line (but not on the button), the record is opened in the s <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.

Bug Tracker

@@ -416,6 +419,10 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
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 000000000..78acc1178 --- /dev/null +++ b/web_widget_open_tab/views/ir_model_views.xml @@ -0,0 +1,13 @@ + + + + ir.model.view.form + ir.model + + + + + + + +