ODOO18 表单操作时,一个奇怪的现象便是修改后虽然出现了保存按扭,但是当你退回来列表时,它会自动保存,这样的话这个保存按扭实际上就没有意义,并且自动保存也是个费劲的机制,一不小心点到,然后还保存了,后面查都不好查。所以,最终还是处理下让它灰复过来,关键代码如下:
/** @odoo-module **/
import { patch } from "@web/core/utils/patch";
import { FormController } from "@web/views/form/form_controller";
import {
ConfirmationDialog,
} from "@web/core/confirmation_dialog/confirmation_dialog";
import { _t } from "@web/core/l10n/translation";
patch(FormController.prototype, {
async beforeLeave() {
if (this.model.root.dirty) {
const needSave = await this.confirmLeave();
if (!needSave) {
return true;
} else {
return this.save({
reload: false,
onError: this.onSaveError.bind(this),
});
}
}
},
confirmLeave() {
return new Promise((resolve, reject) => {
this.dialogService.add(ConfirmationDialog, {
body: _t("Are you sure that you want to save this record?"),
confirmLabel: _t("Save"),
confirm: () => {
resolve(true);
},
cancel: () => {
resolve(false);
}
});
});
},
});