diff --git a/web_m2x_dialog_no_create/README.rst b/web_m2x_dialog_no_create/README.rst new file mode 100644 index 0000000..831ec14 --- /dev/null +++ b/web_m2x_dialog_no_create/README.rst @@ -0,0 +1,95 @@ +============================ +No Create from Search Dialog +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:69dc2f102ac598b442a63497bebbd4cd7a30112caf33e342a77dbb4037f48fcb + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/18.0/web_m2x_dialog_no_create + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_m2x_dialog_no_create + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module hides the **New** button in many2one and many2many search +dialogs by default, preventing users from creating records directly from +the dialog. + +An allowlist of models can be configured per company in *Settings > +General Settings > Search Dialog*, so the New button is shown only for +selected models. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To allow creation from the search dialog for specific models: + +1. Go to **Settings > General Settings > Search Dialog**. +2. Add models to the **Allow Create from Search Dialog** field and save. + +The setting is company-dependent, so each company can have its own +allowlist. A page refresh may be needed for changes to take effect. + +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 +------- + +* Quartile + +Contributors +------------ + +- `Quartile `__: + + - Yoshi Tashiro + +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_m2x_dialog_no_create/__init__.py b/web_m2x_dialog_no_create/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/web_m2x_dialog_no_create/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/web_m2x_dialog_no_create/__manifest__.py b/web_m2x_dialog_no_create/__manifest__.py new file mode 100644 index 0000000..c9d2aa8 --- /dev/null +++ b/web_m2x_dialog_no_create/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "No Create from Search Dialog", + "version": "18.0.1.0.0", + "category": "Technical", + "summary": "Hide New button in many2one/many2many search dialogs", + "author": "Quartile, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", + "license": "AGPL-3", + "depends": ["base_setup"], + "data": [ + "views/res_config_settings_views.xml", + ], + "assets": { + "web.assets_backend": [ + "web_m2x_dialog_no_create/static/src/select_create_dialog.esm.js", + "web_m2x_dialog_no_create/static/src/select_create_dialog.xml", + ], + }, + "installable": True, +} diff --git a/web_m2x_dialog_no_create/models/__init__.py b/web_m2x_dialog_no_create/models/__init__.py new file mode 100644 index 0000000..c674f0d --- /dev/null +++ b/web_m2x_dialog_no_create/models/__init__.py @@ -0,0 +1,3 @@ +from . import ir_http +from . import res_company +from . import res_config_settings diff --git a/web_m2x_dialog_no_create/models/ir_http.py b/web_m2x_dialog_no_create/models/ir_http.py new file mode 100644 index 0000000..f755877 --- /dev/null +++ b/web_m2x_dialog_no_create/models/ir_http.py @@ -0,0 +1,16 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class IrHttp(models.AbstractModel): + _inherit = "ir.http" + + def session_info(self): + result = super().session_info() + company = self.env.company + result["web_m2x_dialog_no_create"] = { + "allowed_models": company.m2x_dialog_create_model_ids.mapped("model"), + } + return result diff --git a/web_m2x_dialog_no_create/models/res_company.py b/web_m2x_dialog_no_create/models/res_company.py new file mode 100644 index 0000000..388101e --- /dev/null +++ b/web_m2x_dialog_no_create/models/res_company.py @@ -0,0 +1,13 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + m2x_dialog_create_model_ids = fields.Many2many( + "ir.model", + string="Allow Create from Search Dialog", + ) diff --git a/web_m2x_dialog_no_create/models/res_config_settings.py b/web_m2x_dialog_no_create/models/res_config_settings.py new file mode 100644 index 0000000..c4834d0 --- /dev/null +++ b/web_m2x_dialog_no_create/models/res_config_settings.py @@ -0,0 +1,13 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + m2x_dialog_create_model_ids = fields.Many2many( + related="company_id.m2x_dialog_create_model_ids", + readonly=False, + ) diff --git a/web_m2x_dialog_no_create/pyproject.toml b/web_m2x_dialog_no_create/pyproject.toml new file mode 100644 index 0000000..4231d0c --- /dev/null +++ b/web_m2x_dialog_no_create/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/web_m2x_dialog_no_create/readme/CONFIGURE.md b/web_m2x_dialog_no_create/readme/CONFIGURE.md new file mode 100644 index 0000000..dbb2d30 --- /dev/null +++ b/web_m2x_dialog_no_create/readme/CONFIGURE.md @@ -0,0 +1,7 @@ +To allow creation from the search dialog for specific models: + +1. Go to **Settings > General Settings > Search Dialog**. +2. Add models to the **Allow Create from Search Dialog** field and save. + +The setting is company-dependent, so each company can have its own allowlist. A page +refresh may be needed for changes to take effect. diff --git a/web_m2x_dialog_no_create/readme/CONTRIBUTORS.md b/web_m2x_dialog_no_create/readme/CONTRIBUTORS.md new file mode 100644 index 0000000..a76ce9d --- /dev/null +++ b/web_m2x_dialog_no_create/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Quartile](https://www.quartile.co): + - Yoshi Tashiro \ No newline at end of file diff --git a/web_m2x_dialog_no_create/readme/DESCRIPTION.md b/web_m2x_dialog_no_create/readme/DESCRIPTION.md new file mode 100644 index 0000000..3e7fef0 --- /dev/null +++ b/web_m2x_dialog_no_create/readme/DESCRIPTION.md @@ -0,0 +1,6 @@ +This module hides the **New** button in many2one and many2many search dialogs by +default, preventing users from creating records directly from the dialog. + +An allowlist of models can be configured per company in +*Settings > General Settings > Search Dialog*, so the New button is shown only for +selected models. diff --git a/web_m2x_dialog_no_create/static/description/index.html b/web_m2x_dialog_no_create/static/description/index.html new file mode 100644 index 0000000..f0ec382 --- /dev/null +++ b/web_m2x_dialog_no_create/static/description/index.html @@ -0,0 +1,439 @@ + + + + + +No Create from Search Dialog + + + +
+

No Create from Search Dialog

+ + +

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

+

This module hides the New button in many2one and many2many search +dialogs by default, preventing users from creating records directly from +the dialog.

+

An allowlist of models can be configured per company in Settings > +General Settings > Search Dialog, so the New button is shown only for +selected models.

+

Table of contents

+ +
+

Configuration

+

To allow creation from the search dialog for specific models:

+
    +
  1. Go to Settings > General Settings > Search Dialog.
  2. +
  3. Add models to the Allow Create from Search Dialog field and save.
  4. +
+

The setting is company-dependent, so each company can have its own +allowlist. A page refresh may be needed for changes to take effect.

+
+
+

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

+
    +
  • Quartile
  • +
+
+
+

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_m2x_dialog_no_create/static/src/select_create_dialog.esm.js b/web_m2x_dialog_no_create/static/src/select_create_dialog.esm.js new file mode 100644 index 0000000..2d02fbc --- /dev/null +++ b/web_m2x_dialog_no_create/static/src/select_create_dialog.esm.js @@ -0,0 +1,14 @@ +// Copyright 2026 Quartile (https://www.quartile.co) +// License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import {SelectCreateDialog} from "@web/views/view_dialogs/select_create_dialog"; +import {patch} from "@web/core/utils/patch"; +import {session} from "@web/session"; + +patch(SelectCreateDialog.prototype, { + get noCreateFromConfig() { + const config = session.web_m2x_dialog_no_create || {}; + const allowed = config.allowed_models || []; + return !allowed.includes(this.props.resModel); + }, +}); diff --git a/web_m2x_dialog_no_create/static/src/select_create_dialog.xml b/web_m2x_dialog_no_create/static/src/select_create_dialog.xml new file mode 100644 index 0000000..bf3eb42 --- /dev/null +++ b/web_m2x_dialog_no_create/static/src/select_create_dialog.xml @@ -0,0 +1,8 @@ + + + + + !props.noCreate and !noCreateFromConfig + + + diff --git a/web_m2x_dialog_no_create/views/res_config_settings_views.xml b/web_m2x_dialog_no_create/views/res_config_settings_views.xml new file mode 100644 index 0000000..7299719 --- /dev/null +++ b/web_m2x_dialog_no_create/views/res_config_settings_views.xml @@ -0,0 +1,30 @@ + + + + res.config.settings.view.form.inherit.web.m2x.dialog.no.create + res.config.settings + + + + + + + + + + + +