Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
1163 Prikazi

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
Opusti
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
Opusti
Related Posts Odgovori Prikazi Aktivnost
3
mar. 25
19121
2
jan. 25
87
0
dec. 21
3116
1
sep. 20
7726
1
mar. 15
3483