Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
1547 Ansichten

Could someone help me how to patch StockForecasted in Odoo16?

class StockForecasted extends Component{
async _getReportValues(){
this.resModel = this.context.active_model || (this.context.params && this.context.params.active_model);
​....
​}
}

I tried this below code but did not work

/** @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
}
}
}

Browser showed 'undefined'. I think this is because this class is not 'export'. But I cannot export this class. This is Odoo code base.

Avatar
Verwerfen
Beste Antwort

Hi,

You have to first export this class and then patch it, Can you just update the code like this and try,

import { patch } from '@web/core/utils/patch';

import { StockForecasted } from "@stock/stock_forecasted/stock_forecasted";


export default class TestMyStockStockForecasted extends 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

}

}

}

}

}


patch(StockForecasted.prototype, 'test_my_stock.StockForecasted', {

TestMyStockStockForecasted,

});


Thanks

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Apr. 24
2175
0
Apr. 24
1036
0
Okt. 23
1084
0
Sept. 24
2055
1
Aug. 24
2773