تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
1769 أدوات العرض

In odoo17 i written code in javascript which actually fetch the gps coordinates from user and then call backend python method which use this coordinates to give route from user's location to task location.


For that when i define 

odoo.define('industry_fsm.user_location', function (require) {
'use strict';

var rpc = require('web.rpc');


I'm getting error and even my odoo page not loading. when i inspect can see below error:

Uncaught Error: Dependencies should be defined by an array

then when i use [], before function,

odoo.define('industry_fsm.user_location',[] function (require) {
'use strict';

var rpc = require('web.rpc');
    function callPythonMethod(param1, param2) {
        return rpc.query({
​model: 'project.task',
            method: 'action_fsm_navigate',
            args: [param1, param2],
        }).then(function (result) {
            console.log(result); // Handle the result from the Python method
        }).catch(function (error) {
            console.error('Error:', error);
        });
    }


The page is loading properly but when the javascript method which actually call the python method is trigger I got the below error:


UncaughtClientError > TypeError


Uncaught Javascript Error > Cannot read properties of undefined (reading 'query')


TypeError: Cannot read properties of undefined (reading 'query')



الصورة الرمزية
إهمال
الكاتب أفضل إجابة

I got the answer that in Odoo17, Instead of using the custom AMD module system (odoo.define and require), Odoo now encourages using the ES6 import syntax, which is widely adopted across the JavaScript ecosystem.

Example Code:



/** @odoo-module **/

import { jsonrpc } from "@web/core/network/rpc_service";

async function callPythonMethod(user_lat, user_lon) {
    alert("callPythonMethod function called");
    try {
        const result = await jsonrpc('/controller_path',
الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
0
سبتمبر 24
850
0
نوفمبر 24
1212
2
يونيو 19
6895
3
أكتوبر 18
14492
1
يونيو 25
3597