Browse Source

May 31: [FIX] Bug Fixed 'auto_save_restrict'

pull/313/merge
Cybrosys Technologies 2 months ago
parent
commit
8d21036ab3
  1. 5
      auto_save_restrict/__manifest__.py
  2. 5
      auto_save_restrict/doc/RELEASE_NOTES.md
  3. 65
      auto_save_restrict/static/src/js/form_controller.js
  4. 103
      auto_save_restrict/static/src/js/view_button.js

5
auto_save_restrict/__manifest__.py

@ -21,7 +21,7 @@
############################################################################# #############################################################################
{ {
'name': 'Auto Save Restrict', 'name': 'Auto Save Restrict',
'version': '17.0.1.0.0', 'version': '17.0.1.0.3',
'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'
@ -36,7 +36,8 @@
'assets': { 'assets': {
'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'
], ],
}, },
'images': ['static/description/banner.png'], 'images': ['static/description/banner.png'],

5
auto_save_restrict/doc/RELEASE_NOTES.md

@ -15,3 +15,8 @@
#### Version 17.0.1.0.2 #### Version 17.0.1.0.2
##### BUG FIX ##### BUG FIX
- Fixed the issue in the form where the popup appeared repeatedly - Fixed the issue in the form where the popup appeared repeatedly
#### 31.05.2025
#### Version 17.0.1.0.3
##### BUG FIX
- Fixed the issue in the smart button where the changes save automatically.

65
auto_save_restrict/static/src/js/form_controller.js

@ -1,33 +1,50 @@
/** @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 { useSetupView } from "@web/views/view_hook"; import { useSetupAction } from "@web/webclient/actions/action_hook";
patch(FormController.prototype, { 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 */ /* Patch FormController to restrict auto save in form views */
patch(FormController.prototype, {
setup(){ setup(){
super.setup(...arguments); super.setup(...arguments);
this.beforeLeaveHook = false
useSetupView({
beforeLeave: () => this.beforeLeave(),
beforeUnload: (ev) => this.beforeUnload(ev),
});
}, },
async beforeLeave() { async beforeLeave() {
/* function will work before leave the form */ const dirty = await this.model.root.isDirty();
if(this.model.root.isDirty && this.beforeLeaveHook == false){ if (dirty) {
if (confirm("Do you want to save changes before leaving?")) { return this._confirmSave();
this.beforeLeaveHook = true }
await this.model.root.save({ },
reload: false,
onError: this.onSaveError.bind(this), beforeUnload() {},
});
} else { async _confirmSave() {
this.beforeLeaveHook = true let _continue = true;
this.model.root.discard(); await new Promise((resolve) => {
} this.dialogService.add(SettingsConfirmationDialog, {
} body: _t("Would you like to save your changes?"),
}, confirm: async () => {
beforeUnload: async (ev) => { await this.save();
ev.preventDefault(); // 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();
},
stayHere: () => {
_continue = false;
resolve();
},
});
});
return _continue;
}
}); });

103
auto_save_restrict/static/src/js/view_button.js

@ -0,0 +1,103 @@
/** @odoo-module */
import { patch } from "@web/core/utils/patch";
import { ViewButton } from "@web/views/view_button/view_button";
import { SettingsConfirmationDialog } from "@web/webclient/settings_form_view/settings_confirmation_dialog";
import { useService } from "@web/core/utils/hooks";
import { _t } from "@web/core/l10n/translation";
import { pick } from "@web/core/utils/objects";
patch(ViewButton.prototype, {
setup() {
super.setup(...arguments);
this.dialogService = useService("dialog");
},
async onClick(ev) {
const proceed = await this._confirmSave();
if (!proceed) {
return;
}
if (this.props.tag === "a") {
ev.preventDefault();
}
if (this.props.onClick) {
return this.props.onClick();
}
},
discard() {
const model = this.props.record || this.props.model;
if (!model) {
console.warn("No model available to discard or save.");
return;
}
this.env.onClickViewButton({
clickParams: {
name: "cancel",
type: "object",
special: "cancel",
},
getResParams: () =>
pick(model, "context", "evalContext", "resModel", "resId", "resIds"),
});
},
async _confirmSave() {
let _continue = true;
await new Promise((resolve) => {
this.dialogService.add(SettingsConfirmationDialog, {
body: _t("Would you like to save your changes?"),
confirm: async () => {
// Check if `clickParams` is available
const clickParams = this.clickParams || {
name: "execute",
type: "object",
};
const model = this.props.record || this.props.model;
if (model) {
await this.env.onClickViewButton({
clickParams,
getResParams: () =>
pick(
model,
"context",
"evalContext",
"resModel",
"resId",
"resIds"
),
});
} else {
console.warn("No model available to execute save.");
}
_continue = true;
resolve();
},
cancel: async () => {
const model = this.props.record || this.props.model;
if (model) {
await model?.discard?.();
await model?.save?.();
} else {
console.warn("No model available to discard or save.");
}
_continue = true;
resolve();
},
stayHere: () => {
_continue = false;
resolve();
},
});
});
return _continue;
},
});
Loading…
Cancel
Save