Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
1080 Vizualizări

I am currently working on Odoo 16 and I am trying to add a confirmation alert when someone tries to change the stage of any record using the statusbar widget.


https://i.postimg.cc/XqNWrkbg/Captura-de-pantalla-2024-10-23-184541.png


Basically, when you click on any stage, it switches to that one, but what I want is that when you try to switch stages, there is a modal/alert where you have to confirm or cancel the changes, and I want it to work on ALL status bars of ANY model. That's it.


I tried a lot of things, but nothing worked. I created a new custom module and tried the following as a test:


custom_addons/custom_stage_confirmation/static/src/js/stage_confirmation.js:

/** @odoo-module **/

import { patch } from "@web/core/utils/patch";
import { registry } from "@web/core/registry";
import { FormController } from "@web/views/form/form_controller";

// Obtener el registro de vistas (viewRegistry)
const viewRegistry = registry.category('views');

// Parchear el controlador del formulario
patch(FormController.prototype, 'custom_stage_confirmation', {
    async _onFieldChanged(event) {
        // Llamar al super para mantener la funcionalidad original
        await this._super(...arguments);

        // Verificar si el campo 'stage_id' ha sido cambiado
        if (event.data.changes && event.data.changes.stage_id) {
            const newStageId = event.data.changes.stage_id[1]; // Obtiene el nombre del nuevo stage
            console.log('El stage_id ha cambiado a:', newStageId); // Log del nuevo stage_id
            this.displayNotification({
                type: 'info',
                title: 'Cambio de etapa',
                message: 'El stage_id ha cambiado a: ' + newStageId,
            });
        } else {
            console.log('No se ha cambiado el stage_id.');
        }
    },
});

// Registrar la vista para asegurarse de que el controlador parcheado se utiliza en la vista de formulario
viewRegistry.add('stage_confirmation', FormController);

In the manifest.py:

# -*- coding: utf-8 -*-
{
    'name': "custom_stage_confirmation",
    'author': "Marín",
    'category': 'Uncategorized',
    'version': '0.1',
    'depends': ['web', 'base'],
    'data': [
        # 'security/ir.model.access.csv',
        'views/views.xml',
        'views/templates.xml',
    ],
    'assets': {
        'web.assets_backend': [
            'custom_stage_confirmation/static/src/js/stage_confirmation.js',
        ],
    },
}


Note: All the scripts are loaded, and there are no errors, this simply doesn't do anything.

I swear I don't know what to do, there is no documentation on FormController, which is the closest thing I found, but it doesn't work. I would appreciate any help. Thanks a lot!

Imagine profil
Abandonează
Cel mai bun răspuns

Hello Andres, How did you solve the problem? I'm struggling with the same thing and can't find the key. Greetings!

Imagine profil
Abandonează
Autor Cel mai bun răspuns

Well, I fixed it, thanks.

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
apr. 25
1317
0
iul. 24
990
Odoo App Rezolvat
1
nov. 23
1869
0
mai 24
1577
0
sept. 23
2529