콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
9089 화면

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
4138
1
12월 22
3626
3
3월 25
7705
0
1월 24
1443
1
10월 23
3808