Browse Source

July 05: [FIX] Bug Fixed 'auto_save_restrict'

17.0
Cybrosys Technologies 1 week ago
parent
commit
711d4ef45c
  1. 4
      auto_save_restrict/__manifest__.py
  2. 5
      auto_save_restrict/doc/RELEASE_NOTES.md
  3. 32
      auto_save_restrict/static/src/js/form_controller.js

4
auto_save_restrict/__manifest__.py

@ -21,7 +21,7 @@
############################################################################# #############################################################################
{ {
'name': 'Auto Save Restrict', 'name': 'Auto Save Restrict',
'version': '17.0.1.0.3', 'version': '17.0.1.0.4',
'category': 'Extra Tools', 'category': 'Extra Tools',
'summary': """Restrict auto save in all models""", 'summary': """Restrict auto save in all models""",
'description': 'Using this module,we can restrict' 'description': 'Using this module,we can restrict'
@ -37,7 +37,7 @@
'web.assets_backend': [ 'web.assets_backend': [
'auto_save_restrict/static/src/js/form_controller.js', 'auto_save_restrict/static/src/js/form_controller.js',
'auto_save_restrict/static/src/js/list_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'], 'images': ['static/description/banner.png'],

5
auto_save_restrict/doc/RELEASE_NOTES.md

@ -20,3 +20,8 @@
#### Version 17.0.1.0.3 #### Version 17.0.1.0.3
##### BUG FIX ##### BUG FIX
- Fixed the issue in the smart button where the changes save automatically. - 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.

32
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 { FormController } from "@web/views/form/form_controller";
import { patch } from "@web/core/utils/patch"; import { patch } from "@web/core/utils/patch";
import { useSetupAction } from "@web/webclient/actions/action_hook";
import { _t } from "@web/core/l10n/translation"; import { _t } from "@web/core/l10n/translation";
import { SettingsConfirmationDialog } from "@web/webclient/settings_form_view/settings_confirmation_dialog"; 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, { patch(FormController.prototype, {
setup(){ async beforeLeave() {
super.setup(...arguments);
},
async beforeLeave() {
const dirty = await this.model.root.isDirty(); const dirty = await this.model.root.isDirty();
if (dirty) { if (dirty) {
return this._confirmSave(); return this._confirmSave();
} }
return true;
}, },
beforeUnload() {}, beforeUnload() {},
async _confirmSave() { async _confirmSave() {
let _continue = true; let _continue = true;
await new Promise((resolve) => { await new Promise((resolve) => {
this.dialogService.add(SettingsConfirmationDialog, { this.dialogService.add(SettingsConfirmationDialog, {
body: _t("Would you like to save your changes?"), body: _t("Would you like to save your changes?"),
confirm: async () => { confirm: async () => {
await this.save(); 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; _continue = true;
resolve(); resolve();
}, },
cancel: async () => { cancel: async () => {
await this.model.root.discard(); await this.model.root.discard();
await this.model.root.save();
_continue = true; _continue = true;
resolve(); resolve();
}, },
@ -46,5 +41,14 @@ patch(FormController.prototype, {
}); });
}); });
return _continue; return _continue;
} },
async onPagerUpdate(value) {
const proceed = await this.beforeLeave();
if (!proceed) {
return;
}
await this.model.root.discard();
return _superOnPagerUpdate.call(this, value);
},
}); });

Loading…
Cancel
Save