diff --git a/setup/web_copy_confirm/odoo/addons/web_copy_confirm b/setup/web_copy_confirm/odoo/addons/web_copy_confirm new file mode 120000 index 000000000..d8928fa7c --- /dev/null +++ b/setup/web_copy_confirm/odoo/addons/web_copy_confirm @@ -0,0 +1 @@ +../../../../web_copy_confirm \ No newline at end of file diff --git a/setup/web_copy_confirm/setup.py b/setup/web_copy_confirm/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/web_copy_confirm/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_copy_confirm/README.rst b/web_copy_confirm/README.rst new file mode 100644 index 000000000..466d6171a --- /dev/null +++ b/web_copy_confirm/README.rst @@ -0,0 +1,83 @@ +================================================= +Show confirmation dialogue before copying records +================================================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/16.0/web_copy_confirm + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_copy_confirm + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/162/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module will show a confirmation dialog when the user selects the +`Duplicate` option from the `Action` dropdown in the standard form view. + +**Table of contents** + +.. contents:: + :local: + +Changelog +========= + +14.0.1.0.0 (2020-01-04) +~~~~~~~~~~~~~~~~~~~~~~~ +* [PORT] Ported to V14 + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Dynapps + +Contributors +~~~~~~~~~~~~ + +* Stefan Rijnhart +* Robin Conjour +* Dhara Solanki + +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_copy_confirm/__init__.py b/web_copy_confirm/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/web_copy_confirm/__manifest__.py b/web_copy_confirm/__manifest__.py new file mode 100644 index 000000000..48b03dbdd --- /dev/null +++ b/web_copy_confirm/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright (C) 2018 DynApps +# @author Stefan Rijnhart +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Show confirmation dialogue before copying records", + "version": "16.0.1.0.0", + "author": "Dynapps,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", + "license": "AGPL-3", + "category": "Tools", + "depends": [ + "web", + ], + "assets": { + "web.assets_backend": [ + "web_copy_confirm/static/src/js/web_copy_confirm.esm.js", + ], + "web.qunit_suite_tests": [ + "web_copy_confirm/static/tests/**/*", + ], + }, + "installable": True, +} diff --git a/web_copy_confirm/i18n/de.po b/web_copy_confirm/i18n/de.po new file mode 100644 index 000000000..d9ef7a0e8 --- /dev/null +++ b/web_copy_confirm/i18n/de.po @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_copy_confirm +# +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_copy_confirm +#. openerp-web +#: code:addons/web_copy_confirm/static/src/js/web_copy_confirm.js:0 +#, python-format +msgid "Are you sure that you would like to copy this record?" +msgstr "Sind Sie sicher, dass Sie diesen Datensatz kopieren möchten?" + +#. module: web_copy_confirm +#. openerp-web +#: code:addons/web_copy_confirm/static/src/js/web_copy_confirm.js:0 +#, python-format +msgid "Duplicate" +msgstr "Duplizieren" diff --git a/web_copy_confirm/i18n/web_copy_confirm.pot b/web_copy_confirm/i18n/web_copy_confirm.pot new file mode 100644 index 000000000..55b6ef2d3 --- /dev/null +++ b/web_copy_confirm/i18n/web_copy_confirm.pot @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_copy_confirm +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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_copy_confirm +#. openerp-web +#: code:addons/web_copy_confirm/static/src/js/web_copy_confirm.js:0 +#, python-format +msgid "Are you sure that you would like to copy this record?" +msgstr "" + +#. module: web_copy_confirm +#. openerp-web +#: code:addons/web_copy_confirm/static/src/js/web_copy_confirm.js:0 +#, python-format +msgid "Duplicate" +msgstr "" diff --git a/web_copy_confirm/readme/CONTRIBUTORS.rst b/web_copy_confirm/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..22134d635 --- /dev/null +++ b/web_copy_confirm/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Stefan Rijnhart +* Robin Conjour +* Dhara Solanki diff --git a/web_copy_confirm/readme/DESCRIPTION.rst b/web_copy_confirm/readme/DESCRIPTION.rst new file mode 100644 index 000000000..926f75008 --- /dev/null +++ b/web_copy_confirm/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module will show a confirmation dialog when the user selects the +`Duplicate` option from the `Action` dropdown in the standard form view. diff --git a/web_copy_confirm/readme/HISTORY.rst b/web_copy_confirm/readme/HISTORY.rst new file mode 100644 index 000000000..c7fc41b79 --- /dev/null +++ b/web_copy_confirm/readme/HISTORY.rst @@ -0,0 +1,3 @@ +14.0.1.0.0 (2020-01-04) +~~~~~~~~~~~~~~~~~~~~~~~ +* [PORT] Ported to V14 diff --git a/web_copy_confirm/static/description/icon.png b/web_copy_confirm/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/web_copy_confirm/static/description/icon.png differ diff --git a/web_copy_confirm/static/description/index.html b/web_copy_confirm/static/description/index.html new file mode 100644 index 000000000..c0e1132d1 --- /dev/null +++ b/web_copy_confirm/static/description/index.html @@ -0,0 +1,434 @@ + + + + + + +Show confirmation dialogue before copying records + + + +
+

Show confirmation dialogue before copying records

+ + +

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

+

This module will show a confirmation dialog when the user selects the +Duplicate option from the Action dropdown in the standard form view.

+

Table of contents

+ +
+

Changelog

+
+

14.0.1.0.0 (2020-01-04)

+
    +
  • [PORT] Ported to V14
  • +
+
+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Dynapps
  • +
+
+
+

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_copy_confirm/static/src/js/web_copy_confirm.esm.js b/web_copy_confirm/static/src/js/web_copy_confirm.esm.js new file mode 100644 index 000000000..6e1f75ef4 --- /dev/null +++ b/web_copy_confirm/static/src/js/web_copy_confirm.esm.js @@ -0,0 +1,23 @@ +/** @odoo-module **/ + +import {patch} from "web.utils"; +import {ConfirmationDialog} from "@web/core/confirmation_dialog/confirmation_dialog"; +import {_t} from "@web/core/l10n/translation"; +import {FormController} from "@web/views/form/form_controller"; + +patch(FormController.prototype, "DuplicateConfirmation", { + async duplicateRecord() { + var _super = this._super; + await this.dialogService.add(ConfirmationDialog, { + title: _t("Duplicate"), + body: _t("Are you sure that you would like to copy this record?"), + confirm: () => { + _super.apply(this, arguments); + }, + cancel: () => { + // `ConfirmationDialog` needs this prop to display the cancel + // button but we do nothing on cancel. + }, + }); + }, +}); diff --git a/web_copy_confirm/static/tests/confirm_tests.js b/web_copy_confirm/static/tests/confirm_tests.js new file mode 100644 index 000000000..bd1f0e90c --- /dev/null +++ b/web_copy_confirm/static/tests/confirm_tests.js @@ -0,0 +1,91 @@ +odoo.define("web_copy_confirm.confirm_tests", function (require) { + "use strict"; + + /* global QUnit*/ + + var FormView = require("web.FormView"); + var testUtils = require("web.test_utils"); + + var createView = testUtils.createView; + + QUnit.module( + "web_copy_confirm", + { + beforeEach: function () { + this.data = { + partner: { + fields: { + display_name: { + string: "STRING", + type: "char", + default: "Name", + }, + }, + records: [ + { + id: 1, + display_name: "first partner", + }, + ], + onchanges: {}, + }, + }; + }, + }, + function () { + QUnit.test("ask confirmation before duplicate", async function (assert) { + assert.expect(4); + const form = await createView({ + View: FormView, + model: "partner", + data: this.data, + arch: ` +
+ + + `, + viewOptions: { + mode: "edit", + }, + res_id: 1, + }); + + // Validate that partner2 does not exist + assert.strictEqual( + typeof form.model.localData.partner_2, + "undefined", + "Partner 2 shouldn't exist" + ); + + // Trigger onDuplicateRecordConfirm + await form._onDuplicateRecordConfirm(); + + // Validate dialog + var confirmDialog = form.getChildren().pop(); + assert.strictEqual( + confirmDialog.buttons[0].text, + "Ok", + "Ok button is available" + ); + assert.strictEqual( + confirmDialog.$content[0].innerHTML, + "Are you sure that you would like to copy this record?", + "Confirmation text is available" + ); + + // Confirm dialog + await confirmDialog.buttons[0].click(); + + // Validate that copy is created + assert.strictEqual( + form.model.localData.partner_2.data.display_name, + "first partner (copy)", + "Copy is created" + ); + + await testUtils.nextTick(); + form.destroy(); + }); + } + ); +});