Skip to content

suggested code is for odoo old version (i think, because in odoo 18, there is other way.) #247005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nayan00112 opened this issue Apr 20, 2025 · 0 comments
Assignees

Comments

@nayan00112
Copy link

Type: Bug

/** @odoo-module **/

import publicWidget from "@web/legacy/js/public/public_widget";
// import ajax from 'web.ajax';
import { rpc } from "@web/core/network/rpc";

publicWidget.registry.AutovoyageServiceVehicles = publicWidget.Widget.extend({
selector: '.s_services_vehicles',

start: function () {
    console.log('Fetching vehicles...');
    this._fetchVehicles();
    return this._super.apply(this, arguments);
},

_fetchVehicles:async function () {
    // Fetch vehicle data from the server
    await rpc('/autovoyage/get_vehicles', {}).then((vehicles) => {
        console.log('Vehicles fetched:', vehicles);
        this._renderVehicles(vehicles);
    }).catch((error) => {
        console.error('Error fetching vehicles:', error);
    });
},

_renderVehicles: function (vehicles) {
    const container = this.$el.find('.d-flex'); // Find the container for cards
    container.empty(); // Clear any existing content

    vehicles.forEach(vehicle => {
        const cardHtml = `
            <div class="card" style="width: 18rem;">
                <div class="card-body">
                    <h5 class="card-title">${vehicle.name}</h5>
                    <p class="card-text mb-1"><strong>Model:</strong> ${vehicle.vehicle_model || 'N/A'}</p>
                    <p class="card-text mb-1"><strong>Service Provider:</strong> ${vehicle.service_provider || 'N/A'}</p>
                    <p class="card-text mb-1"><strong>Fuel Type:</strong> ${vehicle.vehicle_fule_type || 'N/A'}</p>
                    <p class="card-text mb-2"><strong>Rent/Day:</strong> ₹${vehicle.per_day_cost || 'N/A'}</p>
                    <a href="#" class="btn btn-primary w-100">Book Now</a>
                </div>
            </div>
        `;
        container.append(cardHtml); // Append the card to the container
    });
},

});

export default publicWidget.registry.AutovoyageServiceVehicles;

correct code for odoo 18, (ai give me web.ajax but i usd rpc in above menthoned way, I hope this is help foul for you to develop more accurate copilate)

VS Code version: Code 1.99.3 (17baf84, 2025-04-15T23:18:46.076Z)
OS version: Linux x64 6.11.0-24-generic snap
Modes:

System Info
Item Value
CPUs 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz (8 x 2172)
GPU Status 2d_canvas: unavailable_software
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: disabled_software
multiple_raster_threads: enabled_on
opengl: disabled_off
rasterization: disabled_software
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: unavailable_software
webgl2: unavailable_software
webgpu: disabled_off
webnn: unavailable_software
Load (avg) 1, 1, 1
Memory (System) 7.46GB (1.22GB free)
Process Argv --no-sandbox --force-user-env --crash-reporter-id 887b661c-bcfb-4497-93bd-157be06f8e8b
Screen Reader no
VM 0%
DESKTOP_SESSION ubuntu
XDG_CURRENT_DESKTOP Unity
XDG_SESSION_DESKTOP ubuntu
XDG_SESSION_TYPE wayland
Extensions (26)
Extension Author (truncated) Version
vscode-django bat 1.15.0
python-extension-pack don 1.7.0
code-runner for 0.12.2
copilot Git 1.303.0
copilot-chat Git 0.26.5
OdooSnippets jig 1.5.0
vsc-python-indent Kev 1.21.0
rainbow-csv mec 3.19.0
debugpy ms- 2025.6.0
python ms- 2025.4.0
vscode-pylance ms- 2025.4.1
jupyter ms- 2025.3.0
jupyter-keymap ms- 1.1.2
jupyter-renderers ms- 1.1.0
vscode-jupyter-cell-tags ms- 0.1.9
vscode-jupyter-slideshow ms- 0.1.6
vsliveshare ms- 1.0.5948
odoo-file mvi 0.29.0
autodocstring njp 0.6.1
material-icon-theme PKi 5.21.2
vscode-xml red 0.28.1
LiveServer rit 5.7.9
intellicode-api-usage-examples Vis 0.2.9
vscodeintellicode Vis 1.3.2
jinja who 0.0.8
JavaScriptSnippets xab 1.8.0

(1 theme extensions excluded)

A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
pythonvspyt551cf:31249601
vscod805:30301674
binariesv615:30325510
c4g48928:30535728
azure-dev_surveyone:30548225
vscrp:30673768
962ge761:30959799
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dwnewjupytercf:31046870
pythonrstrctxt:31112756
nativeloc1:31192215
5fd0e150:31155592
dwcopilot:31170013
6074i472:31201624
dwoutputs:31242946
customenabled:31248079
hdaa2157:31222309
copilot_t_ci:31222730
e5gg6876:31282496
pythoneinst12:31285622
bgtreat:31268568
4gafe986:31271826
31787653:31262186
3e8i5726:31271747
996jf627:31283433
useunpkgapi:31288273
7bj51361:31289155
747dc170:31275177
g20af354:31278749
aj953862:31281341
convertfstringf:31288068
gendocf:31288070

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants