跳至内容
菜单
此问题已终结
2 回复
1935 查看

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.

形象
丢弃
编写者 最佳答案

In which file i have to do this??

形象
丢弃
最佳答案

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.

形象
丢弃
相关帖文 回复 查看 活动
2
5月 24
1707
1
2月 24
1551
1
11月 22
5264
2
9月 22
18828
0
2月 22
1529