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..4303c5440 --- /dev/null +++ b/web_copy_confirm/README.rst @@ -0,0 +1,82 @@ +================================================= +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/14.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-14-0/web-14-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/14.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 + +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..600381c0e --- /dev/null +++ b/web_copy_confirm/__manifest__.py @@ -0,0 +1,18 @@ +# 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": "14.0.1.0.0", + "author": "Dynapps,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", + "license": "AGPL-3", + "category": "Tools", + "depends": [ + "web", + ], + "data": [ + "views/assets.xml", + ], + "installable": True, +} 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..4c188ea75 --- /dev/null +++ b/web_copy_confirm/i18n/web_copy_confirm.pot @@ -0,0 +1,21 @@ +# 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" +"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 "" diff --git a/web_copy_confirm/readme/CONTRIBUTORS.rst b/web_copy_confirm/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..6462026c0 --- /dev/null +++ b/web_copy_confirm/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Stefan Rijnhart +* Robin Conjour 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/readme/newsfragments/.gitkeep b/web_copy_confirm/readme/newsfragments/.gitkeep new file mode 100644 index 000000000..e69de29bb 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..c478166b6 --- /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.js b/web_copy_confirm/static/src/js/web_copy_confirm.js new file mode 100644 index 000000000..9bf08e952 --- /dev/null +++ b/web_copy_confirm/static/src/js/web_copy_confirm.js @@ -0,0 +1,50 @@ +// Copyright (C) 2018 DynApps +// @author Stefan Rijnhart +// @author Robin Conjour +// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +odoo.define("web_copy_confirm.web_copy_confirm", function (require) { + "use strict"; + + const Core = require("web.core"); + const FormController = require("web.FormController"); + const Dialog = require("web.Dialog"); + const _t = Core._t; + + return FormController.include({ + /** + * Trigger the confirmation dialog when duplicating records + * @returns {Promise} + * @private + */ + _onDuplicateRecordConfirm: async function () { + Dialog.confirm( + this, + _t("Are you sure that you would like to copy this record?"), + { + confirm_callback: () => this._onDuplicateRecord(), + } + ); + }, + /** + * Override the "duplicate" in the action menu + * @returns {any} + * @private + */ + _getActionMenuItems: function () { + const props = this._super(...arguments); + + if (props && props.items && props.items.other) { + const other_list = props.items.other; + const duplicate_index = other_list.findIndex( + (item) => item.description === _t("Duplicate") + ); + if (other_list[duplicate_index]) { + other_list[duplicate_index].callback = () => + this._onDuplicateRecordConfirm(); + } + } + + return props; + }, + }); +}); 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(); + }); + } + ); +}); diff --git a/web_copy_confirm/views/assets.xml b/web_copy_confirm/views/assets.xml new file mode 100644 index 000000000..205b8b03e --- /dev/null +++ b/web_copy_confirm/views/assets.xml @@ -0,0 +1,30 @@ + + + +