Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
1158 Näkymät

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
Hylkää
Paras vastaus

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
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
3
maalisk. 25
19113
2
tammik. 25
87
0
jouluk. 21
3112
1
syysk. 20
7722
1
maalisk. 15
3483