From a78ba18d84553a01d8d8f86c1b0a9ffd15eac13b Mon Sep 17 00:00:00 2001 From: Robin Conjour Date: Mon, 4 Jan 2021 17:13:35 +0100 Subject: [PATCH] [MIG] web_copy_confirm: Migration to 14.0 --- .../odoo/addons/web_copy_confirm | 1 + .../web_copy_confirm/odoo_addons/__init__.py | 1 - .../odoo_addons/web_copy_confirm | 1 - web_copy_confirm/README.rst | 79 ++-- .../{__openerp__.py => __manifest__.py} | 2 +- web_copy_confirm/i18n/web_copy_confirm.pot | 11 +- web_copy_confirm/readme/CONTRIBUTORS.rst | 2 + web_copy_confirm/readme/DESCRIPTION.rst | 2 + web_copy_confirm/readme/HISTORY.rst | 3 + .../readme/newsfragments/.gitkeep | 0 .../static/description/index.html | 434 ++++++++++++++++++ .../static/src/js/web_copy_confirm.js | 53 ++- .../static/tests/confirm_tests.js | 91 ++++ web_copy_confirm/views/assets.xml | 31 +- 14 files changed, 658 insertions(+), 53 deletions(-) create mode 120000 setup/web_copy_confirm/odoo/addons/web_copy_confirm delete mode 100644 setup/web_copy_confirm/odoo_addons/__init__.py delete mode 120000 setup/web_copy_confirm/odoo_addons/web_copy_confirm rename web_copy_confirm/{__openerp__.py => __manifest__.py} (94%) create mode 100644 web_copy_confirm/readme/CONTRIBUTORS.rst create mode 100644 web_copy_confirm/readme/DESCRIPTION.rst create mode 100644 web_copy_confirm/readme/HISTORY.rst create mode 100644 web_copy_confirm/readme/newsfragments/.gitkeep create mode 100644 web_copy_confirm/static/description/index.html create mode 100644 web_copy_confirm/static/tests/confirm_tests.js 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/odoo_addons/__init__.py b/setup/web_copy_confirm/odoo_addons/__init__.py deleted file mode 100644 index de40ea7ca..000000000 --- a/setup/web_copy_confirm/odoo_addons/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/web_copy_confirm/odoo_addons/web_copy_confirm b/setup/web_copy_confirm/odoo_addons/web_copy_confirm deleted file mode 120000 index 002248f80..000000000 --- a/setup/web_copy_confirm/odoo_addons/web_copy_confirm +++ /dev/null @@ -1 +0,0 @@ -../../../web_copy_confirm \ No newline at end of file diff --git a/web_copy_confirm/README.rst b/web_copy_confirm/README.rst index f347116cd..4303c5440 100644 --- a/web_copy_confirm/README.rst +++ b/web_copy_confirm/README.rst @@ -1,55 +1,82 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 +================================================= +Show confirmation dialogue before copying records +================================================= -================================================= -Show a confirmation dialogue when 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 `More` dropdown in the standard form view. +`Duplicate` option from the `Action` dropdown in the standard form view. -Usage -===== +**Table of contents** -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/162/8.0 +.. 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 smash it by providing detailed and welcomed feedback. +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 ======= -Images ------- +Authors +~~~~~~~ -* Odoo Community Association: `Icon `_. +* Dynapps Contributors ------------- +~~~~~~~~~~~~ * Stefan Rijnhart +* Robin Conjour -Do not contact contributors directly about support or help with technical issues. +Maintainers +~~~~~~~~~~~ -Maintainer ----------- +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org -This module is maintained by the OCA. - 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. -To contribute to this module, please visit https://odoo-community.org. +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/__openerp__.py b/web_copy_confirm/__manifest__.py similarity index 94% rename from web_copy_confirm/__openerp__.py rename to web_copy_confirm/__manifest__.py index 52e009b5e..600381c0e 100644 --- a/web_copy_confirm/__openerp__.py +++ b/web_copy_confirm/__manifest__.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Show confirmation dialogue before copying records", - "version": "8.0.1.0.0", + "version": "14.0.1.0.0", "author": "Dynapps,Odoo Community Association (OCA)", "website": "https://github.com/OCA/web", "license": "AGPL-3", diff --git a/web_copy_confirm/i18n/web_copy_confirm.pot b/web_copy_confirm/i18n/web_copy_confirm.pot index 7ca065c18..4c188ea75 100644 --- a/web_copy_confirm/i18n/web_copy_confirm.pot +++ b/web_copy_confirm/i18n/web_copy_confirm.pot @@ -1,12 +1,12 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * web_copy_confirm +# * web_copy_confirm # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 8.0\n" +"Project-Id-Version: Odoo Server 14.0\n" "Report-Msgid-Bugs-To: \n" -"Last-Translator: <>\n" +"Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -15,8 +15,7 @@ msgstr "" #. module: web_copy_confirm #. openerp-web -#: code:addons/web_copy_confirm/static/src/js/web_copy_confirm.js:9 +#: code:addons/web_copy_confirm/static/src/js/web_copy_confirm.js:0 #, python-format -msgid "Do you really want to copy this record?" +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/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 index 0c58051c2..9bf08e952 100644 --- a/web_copy_confirm/static/src/js/web_copy_confirm.js +++ b/web_copy_confirm/static/src/js/web_copy_confirm.js @@ -1,15 +1,50 @@ // Copyright (C) 2018 DynApps // @author Stefan Rijnhart +// @author Robin Conjour // License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -openerp.web_copy_confirm = function (instance) { - instance.web.FormView.include({ - on_button_duplicate: function () { - var self = this; - this.has_been_loaded.done(function () { - if (confirm(_t("Do you really want to copy this record?"))) { - return self._super.apply(self, arguments); +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 index 0588a6106..205b8b03e 100644 --- a/web_copy_confirm/views/assets.xml +++ b/web_copy_confirm/views/assets.xml @@ -1,17 +1,30 @@ - +