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

Error when using userService("orm") - odoo16

I was on a mission to create a new page, and here's how I did it.


1. root/controller => Create a Controller that renders the root template

@http.route("/tracking", type="http", website=True, csrf=False, auth="public")
def tracking_page(self):
​return http.request.render("tpc_custom_website.tracking_owl")


2. views/template.xml => Create a template containing a div with id root_owl

     

         

             

             

         

     



3. static/src/js => Generate js to use owl framework

import {useState, Component, whenReady, App, onWillStart, mount} from "@odoo/owl"


import {templates} from "@web/core/assets"

import {useService} from "@web/core/utils/hooks";


class TrackingOwl extends Component {

     setup() {

         super.setup();

         this.orm = useService("orm")

     }

}


TrackingOwl.template = "tpc_custom_website.tracking_owl"


whenReady(async () => {

     const tracking_owl_root = document.querySelector("#root_owl")

     if (tracking_owl_root)

         await mount(TrackingOwl, tracking_owl_root, {templates})

});


4. static/src/xml => Create component to mount to root

     

         

Page tracking

     



5. in file __manifest__

"data": [

         'views/template.xml'

     ],

"assets": {

         "web.assets_frontend": [

             '{module_name}/static/src/js/tracking.js',

             '{module_name}/static/src/xml/tracking_page.xml'

         ]

     },


and I get an error in step 3 with the message "TypeError: Cannot use 'in' operator to search for 'orm' in undefined"


So how do I fix this error, thank you everyone

아바타
취소
베스트 답변

Hi,

Please go through our blog 'How Does RPC & ORM Calls Works in Odoo 16'


https://www.cybrosys.com/blog/how-does-rpc-and-orm-calls-works-in-odoo-16


Hope it helps

아바타
취소

I can't use it inside AbstractController. I try extend gantt controller (which extend from AbstractController) and add a function to get project_id from python method. Then I got error Uncaught Promise > Cannot read properties of null (reading 'component')

But when I'm using it inside a class that extend CharField class, it's working

관련 게시물 답글 화면 활동
3
12월 23
6560
2
7월 23
4011
1
6월 24
2087
0
1월 24
1595
2
6월 25
4281