Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
2297 Tampilan

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

Avatar
Buang
Jawaban Terbai

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

Avatar
Buang

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

Post Terkait Replies Tampilan Aktivitas
3
Des 23
5766
2
Jul 23
3190
1
Jun 24
1474
0
Jan 24
1059
2
Apr 24
4187