Hello,
I am developing an Odoo module and need to ensure that logs are not saved until an API call is completed. At the moment, Odoo automatically saves when I leave the page or even when I activate the API call using a button.
causing duplicate records (The automatic one and the one that comes after the API call).
I tried disabling autosave globally and customizing the beforeLeave logic for my specific model,
but it interferes with normal behavior in other modules.
So I have some doubts
-How can I avoid saving until the API call finishes?
-If using OWL, how can I make this behavior apply only to my module in question?
/** @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); // Solo aplica para el modelo específico if (this.props.resModel === 'my.module') { useSetupView({ beforeLeave: () => this.beforeLeave(), }); } }, async beforeLeave() { if (this.props.resModel === 'my.module' && this.model.root.isDirty) { this.model.root.discard(); }else{ this.model.root.save({ reload: false, onError: this.onSaveError.bind(this), }); // window.location.reload(); } } });
Any suggestions would be appreciated!
Thank you!