有人可以帮我如何在 Odoo16 中修补 StockForecasted 吗?
class StockForecasted extends Component{
async _getReportValues(){
this.resModel = this.context.active_model || (this.context.params && this.context.params.active_model);
....
}
}
我尝试了下面的代码,但没有成功
/** @odoo-module **/
import { patch } from '@web/core/utils/patch';
import { StockForecasted } from "@stock/stock_forecasted/stock_forecasted";
console.log(StockForecasted)
patch(StockForecasted.prototype, 'test_my_stock.StockForecasted', {
async _getReportValues(){
console.log('_getReportValuesInherit')
this.resModel = this.context.active_model || (this.context.params && this.context.params.active_model);
if (!this.resModel) {
if (this.props.action.res_model) {
const actionModel = await this.orm.read('ir.model', [Number(this.props.action.res_model)], ['model']);
if (actionModel.length && actionModel[0].model) {
this.resModel = actionModel[0].model
}
} else if (this.props.action._originalAction) {
const originalContextAction = JSON.parse(this.props.action._originalAction).context;
if (originalContextAction) {
this.resModel = originalContextAction.active_model
}
}
}
浏览器显示“未定义”。我认为这是因为这个类不是“导出”的。但我无法导出这个类。这是 Odoo 代码库。
最佳答案
发生这种情况是因为 Odoo 无法从 stock/stock_forecasted/stock_forecasted
导入它
您应该在控制台中看到以下错误:
TypeError: StockForecasted is undefined
如果您检查stock/static/src/stock_forecasted/stock_forecasted.js
文件中,您会看到他们添加了 StockForecasted
组件至actions
注册表为 replenish_report
示例:
/** @odoo-module **/
import { patch } from '@web/core/utils/patch';
import { registry } from "@web/core/registry";
import "@stock/stock_forecasted/stock_forecasted";
const actionRegistry = registry.category("actions");
const StockForecasted = actionRegistry.get('replenish_report');
patch(StockForecasted.prototype, 'test_my_stock.StockForecasted', {
async _getReportValues(){
console.log('_getReportValuesInherit')
await this._super(...arguments);
}
});
关于javascript - 修补 StockForecasted Javascript Odoo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76791546/