İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
1169 Görünümler

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
Vazgeç
En İyi Yanıt

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

Avatar
Vazgeç
Üretici En İyi Yanıt

Well, I fixed it, thanks.

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Nis 25
1410
0
Tem 24
1106
Odoo App Çözüldü
1
Kas 23
2008
0
May 24
1727
0
Eyl 23
2672