コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
7942 ビュー

I want to add some custom function or code in ProductScreen class in POS. But I didn't find any appropriate example. How can I extend odoo owl Component and override or add new function on it.

アバター
破棄
著作者 最善の回答
odoo.define('uni_pos.ProductScreen_PosLineDiscount', function(require) {
'use strict';
const Registries = require('point_of_sale.Registries');
const ProductScreen = require('point_of_sale.ProductScreen');

const PosLineDiscount = (ProductScreen) => class extends ProductScreen {

async _clickProduct(event) {
if (!this.currentOrder) {
this.env.pos.add_new_order();
}
const product = event.detail;
const options = await this._getAddProductOptions(product);
// Do not add product if options is undefined.
if (!options) return;
// Add the product after having the extra information.
this.currentOrder.add_product(product, options);
// this.currentOrder.get_selected_orderline().set_discount(5)
console.log('Product Add')

try {
NumberBuffer.reset();
}
catch(err) {
console.log(err)
}
}
};
Registries.Component.extend(ProductScreen, PosLineDiscount);
return ProductScreen;

});

Here is the answer, for extending a OWL class and adding and overriding a function.

アバター
破棄
最善の回答

You can use "patch"

/** @odoo-module **/
import { ClassYouWantToModify } from "path";

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

patch(ClassYouWantToModify.prototype, "ModuleName.ClassYouWantToModify", {

    /**     

     ​* @override the function or add new one     

    */

});

アバター
破棄
関連投稿 返信 ビュー 活動
1
5月 23
3519
1
12月 22
3063
3
3月 25
6086
0
1月 24
940
1
10月 23
3277