From e0f55f44588cc33732c308713f00505465c5b504 Mon Sep 17 00:00:00 2001 From: Marc Durepos Date: Wed, 10 Sep 2025 13:42:57 -0400 Subject: [PATCH] [MIG] confirm_many2one_create to 18.0 --- confirm_many2one_create/__init__.py | 0 confirm_many2one_create/__manifest__.py | 37 +++++++++++++++++++ .../static/src/js/many2one_field.esm.js | 29 +++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 confirm_many2one_create/__init__.py create mode 100644 confirm_many2one_create/__manifest__.py create mode 100644 confirm_many2one_create/static/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..b597da5 --- /dev/null +++ b/confirm_many2one_create/__manifest__.py @@ -0,0 +1,37 @@ +# +# 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": "18.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/static/src/js/many2one_field.esm.js", + ], + }, + "installable": True, + "auto_install": False, +} diff --git a/confirm_many2one_create/static/src/js/many2one_field.esm.js b/confirm_many2one_create/static/src/js/many2one_field.esm.js new file mode 100644 index 0000000..5a0e352 --- /dev/null +++ b/confirm_many2one_create/static/src/js/many2one_field.esm.js @@ -0,0 +1,29 @@ +/** @odoo-module **/ + +import {Many2OneField, m2oTupleFromData} from "@web/views/fields/many2one/many2one_field"; +import {patch} from "@web/core/utils/patch"; + +patch(Many2OneField.prototype, { + /** + * The original Many2OneField already has a quickCreate method and an openConfirmationDialog method. + * The quickCreate method directly updates the record, while openConfirmationDialog shows a dialog + * before calling quickCreate. + * + * We just need to modify the Many2XAutocompleteProps getter to use openConfirmationDialog + * instead of quickCreate for the quickCreate property. + */ + get Many2XAutocompleteProps() { + const props = super.Many2XAutocompleteProps; + + // If quickCreate is defined, replace it with openConfirmationDialog + if (props.quickCreate && this.openConfirmationDialog) { + // Store the original quickCreate function + const originalQuickCreate = props.quickCreate; + + // Replace with openConfirmationDialog + props.quickCreate = (name) => this.openConfirmationDialog(name); + } + + return props; + }, +});