From 8e5185a80f01736ea04ff0e21b9ec2368dc44350 Mon Sep 17 00:00:00 2001 From: Marc Durepos Date: Fri, 2 Aug 2024 14:41:56 -0400 Subject: [PATCH] [ADD] new module confirm_many2one_create Pure JS module to override the behaviour of Many2One fields, causing them to open a confirmation dialog when the user selects the "Create" option from the autocomplete list of a Many2One field with quick create enabled. --- confirm_many2one_create/__init__.py | 0 confirm_many2one_create/__manifest__.py | 35 +++++++++++++++++++ .../src/js/many2one_field.esm.js | 12 +++++++ 3 files changed, 47 insertions(+) create mode 100644 confirm_many2one_create/__init__.py create mode 100644 confirm_many2one_create/__manifest__.py create mode 100644 confirm_many2one_create/src/js/many2one_field.esm.js diff --git a/confirm_many2one_create/__init__.py b/confirm_many2one_create/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/confirm_many2one_create/__manifest__.py b/confirm_many2one_create/__manifest__.py new file mode 100644 index 0000000..248bf57 --- /dev/null +++ b/confirm_many2one_create/__manifest__.py @@ -0,0 +1,35 @@ +# +# Bemade Inc. +# +# Copyright (C) 2023-June Bemade Inc. (). +# Author: Marc Durepos (Contact : marc@bemade.org) +# +# This program is under the terms of the GNU Lesser General Public License, +# version 3. +# +# For full license details, see https://www.gnu.org/licenses/lgpl-3.0.en.html. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# +{ + "name": "Many2one Confirm Creation", + "version": "17.0.1.0.0", + "summary": "Pop up a confirmation dialog when creating via a Many2one field", + "category": "Web", + "author": "Bemade Inc.", + "website": "http://www.bemade.org", + "license": "LGPL-3", + "depends": ["web"], + "data": [], + "assets": { + "web.assets_backend": ["confirm_many2one_create/src/js/many2one_field.esm.js"] + }, + "installable": True, + "auto_install": False, +} diff --git a/confirm_many2one_create/src/js/many2one_field.esm.js b/confirm_many2one_create/src/js/many2one_field.esm.js new file mode 100644 index 0000000..02d0681 --- /dev/null +++ b/confirm_many2one_create/src/js/many2one_field.esm.js @@ -0,0 +1,12 @@ +/** @odoo-module **/ + +import {Many2OneField} from "@web/views/fields/many2one/many2one_field"; +import {patch} from "@web/core/utils/patch"; + +patch(Many2OneField.prototype, { + get Many2XAutocompleteProps() { + const props = super.Many2XAutocompleteProps(); + props.quickCreate = this.openConfirmationDialog.bind(this); + return props; + }, +});