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

I have some problems with loading the appropriate dependencies in odoo18 / web.ajax and and some other like web.core, 

When I comments out the web.ajax, my JS is loaded but Cann some point out what is going wrong, and where cann i find the web.ajax in my odoo18.

console.log("💡 Breadcrumb JS loaded");

const ajax = require('web.ajax');

document.addEventListener("click", function (ev) {
const link = ev.target.closest(".o_breadcrumb_link");
if (!link) return;

ev.preventDefault();

const model = link.dataset.model;
const resId = parseInt(link.dataset.id, 10);

if (model && resId) {
const action = {
type: 'ir.actions.act_window',
res_model: model,
res_id: resId,
view_mode: 'form',
target: 'current',
};

// Use legacy ActionManager through WebClient
const $el = $('.o_web_client');
const actionManager = $el.data('action_manager');
if (actionManager) {
actionManager.do_action(action);
} else {
console.warn("Action manager not available.");
}
}
});
الصورة الرمزية
إهمال

There is no web.ajax in Odoo 18.

أفضل إجابة

Replace:

const ajax = require('web.ajax');

With:

import { ajax } from "@web/core/ajax";

And make sure the script is loaded using the assets bundle system properly in your module manifest (__manifest__.py).

 Example Working Setup for Odoo 18:

 JS File (breadcrumb_click.js)


import { ajax } from "@web/core/ajax";

import { registry } from "@web/core/registry";


console.log("💡 Breadcrumb JS loaded");


document.addEventListener("click", function (ev) {

    const link = ev.target.closest(".o_breadcrumb_link");

    if (!link) return;


    ev.preventDefault();


    const model = link.dataset.model;

    const resId = parseInt(link.dataset.id, 10);


    if (model && resId) {

        const action = {

            type: 'ir.actions.act_window',

            res_model: model,

            res_id: resId,

            view_mode: 'form',

            target: 'current',

        };


        const webClient = document.querySelector('.o_web_client');

        const actionService = registry.category("services").get("action");


        if (actionService && webClient && webClient.__component__) {

            const env = webClient.__component__.env;

            env.services.action.doAction(action);

        } else {

            console.warn("Could not find action service.");

        }

    }

});


 Debugging Tips:

  • web.ajax in modern Odoo is found at @web/core/ajax.

  • web.core is replaced with specific imports like useService, useState, etc., in OWL.

  • Open the browser DevTools → Sources tab → check if your file is loaded.

  • Ensure your .js file includes /** @odoo-module */ at the top.


Hope It is Useful.

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

For odoo18 we need also in the first line deps[]

odoo.define('your_module.breadcrumb_click_handler', ['@web/core/', '@web/ajax'], function (require) {.....

not sure if this the correct way for odoo 18. because the next wil give the error, can nor not web.ajax en web that this are not loaded

const ajax = require('web.ajax');
const core = require('web.core');

And also the lines

const $el = $('.o_web_client');
const actionManager = $el.data('action_manager');

if (actionManager) {
actionManager.do_action(action);

gives an error that it could not resolve " do_action"

thanx

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

Hii,

Use odoo.define() Properly

Wrap your code like this to ensure dependencies load correctly:

odoo.define('your_module.breadcrumb_click_handler', function (require) {

    "use strict";


    const ajax = require('web.ajax');

    const core = require('web.core');


    console.log("💡Breadcrumb JS loaded");


    document.addEventListener("click", function (ev) {

        const link = ev.target.closest(".o_breadcrumb_link");

        if (!link) return;


        ev.preventDefault();


        const model = link.dataset.model;

        const resId = parseInt( link.dataset.id , 10);


        if (model && resId) {

            const action = {

                type: 'ir.actions.act_window',

                res_model: model,

                res_id: resId,

                view_mode: 'form',

                target: 'current',

            };


            const $el = $('.o_web_client');

            const actionManager = $el.data('action_manager');


            if (actionManager) {

                actionManager.do_action(action);

            } else {

                console.warn("Action manager not available.");

            }

        }

    });

});


Then load it in your view via:

<template id="assets_backend" inherit_id="web.assets_backend" name="Custom Breadcrumb JS">

    <xpath expr="." position="inside">

        <script type="text/javascript" src="/your_module/static/src/js/breadcrumb_click.js"/>

    </xpath>

</template>


You should make sure your file structure is correct

i hope it is usefull

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يوليو 24
1729
0
أبريل 24
1346
5
أغسطس 25
4177
3
يوليو 25
405
1
يونيو 25
585