Skip to Content
Menu
This question has been flagged

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!

Avatar
Discard
Best Answer

Hi,
Either you can add this options="{'autosave': False}" to all fields, am not sure if generically a form has such an option, so you can try adding this to all fields in xml and see if that helps or not.

Also you can checkout this app: https://apps.odoo.com/apps/modules/17.0/auto_save_restrict


Thanks

Avatar
Discard
Related Posts Replies Views Activity
2
Mar 24
16334
0
Dec 21
1826
1
Sep 20
6286
1
Mar 15
2681
2
Jul 23
947