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.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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.
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
2
thg 5 24
|
1706 | ||
|
1
thg 2 24
|
1544 | ||
Access logs on Odoo Community
Đã xử lý
|
|
1
thg 11 22
|
5257 | |
|
2
thg 9 22
|
18786 | ||
|
0
thg 2 22
|
1526 |