Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
2074 Zobrazení

When I am in Form View and the data is filled, refreshing the page automatically saves it. However, I don’t want this to happen. When I refresh, the data should not be saved.

Avatar
Zrušit
Autor Nejlepší odpověď

In which file i have to do this??

Avatar
Zrušit
Nejlepší odpověď

Hi,

By patching FormController, we can restrict auto-save in form views. By restricting the auto-save, the form will not save if we refresh the page.

/** @odoo-module */

import { FormController } from "@web/views/form/form_controller";

import { patch } from "@web/core/utils/patch";

import { useSetupView } from "@web/views/view_hook";

patch(FormController.prototype, {

  setup(){

     super.setup(...arguments);

     this.beforeLeaveHook = false

     useSetupView({

         beforeLeave: () => this.beforeLeave(),

         beforeUnload: (ev) => this.beforeUnload(ev),

     });

  },

  async beforeLeave() {

  /* function will work before leave the form */

     if(this.model.root.isDirty && this.beforeLeaveHook == false){

         if (this.env.searchModel && this.env.searchModel.resModel != 'create.bulk.products') {

             this.beforeLeaveHook = true

             await this.model.root.save({

                 reload: false,

                 onError: this.onSaveError.bind(this),

             });

         } else {

             this.beforeLeaveHook = true

             this.model.root.discard();

         }

     }

  },

  beforeUnload: async (ev) => {

      ev.preventDefault();

  }

});


Hope this helps.

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
kvě 24
1802
1
úno 24
1636
1
lis 22
5402
2
zář 22
19417
0
úno 22
1592