diff --git a/auto_save_restrict/__manifest__.py b/auto_save_restrict/__manifest__.py index bd76fda16..f03418a60 100644 --- a/auto_save_restrict/__manifest__.py +++ b/auto_save_restrict/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################# { 'name': 'Auto Save Restrict', - 'version': '17.0.1.0.3', + 'version': '17.0.1.0.4', 'category': 'Extra Tools', 'summary': """Restrict auto save in all models""", 'description': 'Using this module,we can restrict' @@ -37,7 +37,7 @@ 'web.assets_backend': [ 'auto_save_restrict/static/src/js/form_controller.js', 'auto_save_restrict/static/src/js/list_controller.js', - 'auto_save_restrict/static/src/js/view_button.js' + 'auto_save_restrict/static/src/js/view_button.js', ], }, 'images': ['static/description/banner.png'], diff --git a/auto_save_restrict/doc/RELEASE_NOTES.md b/auto_save_restrict/doc/RELEASE_NOTES.md index edd9d0fc6..681629d72 100644 --- a/auto_save_restrict/doc/RELEASE_NOTES.md +++ b/auto_save_restrict/doc/RELEASE_NOTES.md @@ -20,3 +20,8 @@ #### Version 17.0.1.0.3 ##### BUG FIX - Fixed the issue in the smart button where the changes save automatically. + +#### 02.07.2025 +#### Version 17.0.1.0.4 +##### BUG FIX +- Fixed the issue in the next/previous button where the changes save automatically. diff --git a/auto_save_restrict/static/src/js/form_controller.js b/auto_save_restrict/static/src/js/form_controller.js index f414af71c..e6a1ff2fb 100644 --- a/auto_save_restrict/static/src/js/form_controller.js +++ b/auto_save_restrict/static/src/js/form_controller.js @@ -1,41 +1,36 @@ -/** @odoo-module */ +/** @odoo-module **/ + import { FormController } from "@web/views/form/form_controller"; import { patch } from "@web/core/utils/patch"; -import { useSetupAction } from "@web/webclient/actions/action_hook"; import { _t } from "@web/core/l10n/translation"; import { SettingsConfirmationDialog } from "@web/webclient/settings_form_view/settings_confirmation_dialog"; -/* Patch FormController to restrict auto save in form views */ +// Save original method reference +const _superOnPagerUpdate = FormController.prototype.onPagerUpdate; patch(FormController.prototype, { - setup(){ - super.setup(...arguments); - }, - - async beforeLeave() { + async beforeLeave() { const dirty = await this.model.root.isDirty(); if (dirty) { return this._confirmSave(); } + return true; }, - beforeUnload() {}, + beforeUnload() {}, - async _confirmSave() { + async _confirmSave() { let _continue = true; await new Promise((resolve) => { this.dialogService.add(SettingsConfirmationDialog, { body: _t("Would you like to save your changes?"), confirm: async () => { await this.save(); - // It doesn't make sense to do the action of the button - // as the res.config.settings `execute` method will trigger a reload. _continue = true; resolve(); }, cancel: async () => { await this.model.root.discard(); - await this.model.root.save(); _continue = true; resolve(); }, @@ -46,5 +41,14 @@ patch(FormController.prototype, { }); }); return _continue; - } + }, + + async onPagerUpdate(value) { + const proceed = await this.beforeLeave(); + if (!proceed) { + return; + } + await this.model.root.discard(); + return _superOnPagerUpdate.call(this, value); + }, });