When any control value is modified, close the view, and the current record will update the record. Some data here may be clicked at will rather than what is really needed, but the data is still updated. How to disable this function? Click Save manually instead
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- 客户关系管理
- e-Commerce
- 会计
- 库存
- PoS
- Project
- MRP
此问题已终结
Hi,
By patching FormController, we can restrict auto-save in form views. So ater the patching the data will save only if we save the form manually.Try the following code for patching the form controller:
/** @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 != 'your.model') {
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 it helps.
相关帖文 | 回复 | 查看 | 活动 | |
---|---|---|---|---|
|
3
8月 25
|
2614 | ||
|
1
5月 25
|
2648 | ||
|
1
4月 25
|
3637 | ||
|
1
4月 25
|
4495 | ||
|
1
4月 25
|
1965 |