Skip to Content
Menu
This question has been flagged
2 Replies
1042 Views

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!

Avatar
Discard
Best Answer

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

Avatar
Discard
Author Best Answer

Well, I fixed it, thanks.

Avatar
Discard
Related Posts Replies Views Activity
1
Apr 25
1266
0
Jul 24
962
Odoo App Solved
1
Nov 23
1823
0
May 24
1517
0
Sep 23
2478