Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2363 Lượt xem

I'm developing a new funtionality in Odoo 17 and Owl and I'm trying to inherit the companyService​ service in JavaScript to add some new code inside the computeActiveCompanyIds​ function. I tried using the patch function as shown here:


/** @odoo-module **/

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


export const companyServiceInherit = {
computeActiveCompanyIds(cids) {
​// My code
},
}

patch(companyService, companyServiceInherit);

When I inherit the service this way I'm able to see my new code on the Chrome debug tool but it doesn't execute inside the new function, Odoo just uses the old one.

Is this way the correct one? How else can I try inheriting this service?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

Use the following code to patch the function:

/** @odoo-module **/

import { companyService } from "@web/webclient/company_service";

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


patch(companyService.prototype, {    async setup() {

        super.setup(); // By using the super function, we can execute all parent functions along with ours.

    },    computeActiveCompanyIds(cids) {         // Write your code here

    },});


Please refer to the following blog for understanding the working of patching, with example:


https://www.cybrosys.com/blog/how-to-patch-existing-owl-component-in-odoo-17


Hope it helps.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 8 24
2663
1
thg 12 24
1356
2
thg 4 24
4722
2
thg 4 25
1215
0
thg 4 25
1269