Skip to Content
Menú
This question has been flagged

I'm trying to fetch user coordinates using javascript code and then i want to send it to backend python method, where it was used to find the map from user's location to task location.

My python method works as record level, not model level so i could not able to use decorators (@api.model)

My JS code is as below:


/** @odoo-module **/

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

// Function to send specific coordinates to the backend
async function sendSpecificUserCoordinates() {
    // Specify the desired user coordinates
    const userLatitude = 43.7755099;
    const userLongitude = -79.2943383;

    try {
        // Make the RPC call to the Odoo backend method
        const result = await jsonrpc("/web/dataset/call_kw", {
            model: "res.partner",   // Model name
            method: "action_partner_navigate",  // Method in Python to call
            args: [],  // No ID needed, passing only coordinates
            kwargs: { 'user_lat': userLatitude, 'user_lon': userLongitude }  // Passing coordinates as kwargs
        });

        // Handle the response (e.g., opening the URL for navigation)
        console.log("Navigation URL:", result.url);
        // You can also perform actions like window.open(result.url, '_blank') to open the navigation link

    } catch (error) {
        console.error("Error calling Python method:", error);
    }
}

// Expose the function globally if you plan to use it directly from your HTML button
window.sendSpecificUserCoordinates = sendSpecificUserCoordinates;

My backend python method fetch the task location when user select in the web page and then when user click on the View_Route the JS code should trigger first and send the user's location to python method so its generate whole route from user's location to task location.

Is there any way I can send the user coordinates to backend python method which is actually working with partner coordinates at record level?

Avatar
Descartar
Related Posts Respostes Vistes Activitat
1
de set. 24
1462
0
de nov. 24
711
3
de set. 24
5358
1
de set. 19
10224
3
de des. 23
45297