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

In Odoo 18 I try to use orm to call a method from python level with POS JavaScript  put it not working when I am in PosOrder file 

I try this code 

import { PosOrder } from "@point_of_sale/app/models/pos_order";
import { patch } from "@web/core/utils/patch";
import { useService } from "@web/core/utils/hooks";

patch(PosOrder.prototype, {
setup() {
super.setup(...arguments);
this.orm = useService('orm');
},
})

put it not working, I do not whey this working when I make any other pos prototype files 
I got this error 

TypeError: Cannot read properties of null (reading 'component')

    at useComponent (point_of_sale.assets_prod.min.js:1059:44)

    at useService (point_of_sale.assets_prod.min.js:7979:137)

    at Proxy.setup (point_of_sale.assets_prod.min.js:16608:528)

    at create (point_of_sale.assets_prod.min.js:9253:26)

    at Proxy.create (point_of_sale.assets_prod.min.js:9266:387)

    at Proxy.createNewOrder (point_of_sale.assets_prod.min.js:10181:224)

    at Proxy.createNewOrder (point_of_sale.assets_prod.min.js:16582:828)

    at Proxy.add_new_order (point_of_sale.assets_prod.min.js:10183:18)

    at Proxy.afterProcessServerData (point_of_sale.assets_prod.min.js:10125:331)

    at Proxy.afterProcessServerData (point_of_sale.assets_prod.min.js:16202:465)

and I also try 

const orm = this.env.services.orm;

and also not working 
can any one help me on this 

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

I try this before and not working 

const orm = this.env.services.orm;

I know it may work in many other files but it does not work specifically in this file. You can try it yourself.

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

Hi,


In Odoo 18 POS, you can perform an ORM call  using this.env.services.orm, as shown below.


/** @odoo-module **/

import { PosOrder } from "@point_of_sale/app/models/pos_order";

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

patch(PosOrder.prototype, {

    setup() {

        super.setup(...arguments);

        this.orm = this.env.services.orm;

    },


    async your_function() {

        const result = await this.orm.call('model.name', 'method_name', [args]);

        console.log(result);

    },

});


Hope it helps

Ảnh đại diện
Huỷ bỏ
Tác giả

I try this before and not working
const orm = this.env.services.orm;
I know it may work in many other files but it does not work specifically in this file. You can try it yourself.

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 7 25
165
1
thg 12 24
1428
0
thg 5 22
3035
1
thg 5 24
3236
1
thg 12 23
1559