تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
1108 أدوات العرض

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!

الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Well, I fixed it, thanks.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أبريل 25
1331
0
يوليو 24
1013
Odoo App تم الحل
1
نوفمبر 23
1888
0
مايو 24
1596
0
سبتمبر 23
2545