基本上,当您单击任何阶段时,它会切换到该阶段,但是我想要的是,当您尝试切换阶段时,有一个模态/警报,您必须在其中确认或取消更改,我希望它在任何模型的所有状态栏上工作。就是这样 我尝试了很多事情,但没有任何效果。我创建了一个新的自定义模块,并尝试了以下测试:
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);
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',
],
},
}
注:所有脚本都加载了,没有错误,这根本没有任何作用。我发誓我不知道该怎么办,没有关于formcontroller的文档,这是我发现的最接近的东西,但它行不通。感谢任何帮助。非常感谢!
hello你找到了解决方案吗?