This question has been flagged
3 Replies
583 Views

Hello, 

I am getting this error in this javascript code yet it is working well in Odoo 16.

The following modules are needed by other modules but have not been defined, they may not be present in the correct asset bundle: web.ajax

How do I go about this?
Thanks in advance.

/** @odoo-module **/

odoo.define("dynamic_access_rights.core", [], function(require) {
"use strict";

const ajax = require("web.ajax");
let dynamics = null;

function update_buttons(target_buttons){
for(let button of target_buttons){
let klas = `dynamics-${button.restriction}`
let name = button.name
let buttons1 = $(`button[name='${name}']`)
let buttons2 = $(`.${name}`)
buttons1.each(function (){
$(this).addClass(klas)
})
buttons2.each(function (){
$(this).addClass(klas)
})
}
}
function update_pages(target_pages){
for(let page of target_pages){
let klas = `dynamics-${page.restriction}`
let name = page.name
let anchors = $(`a[role='tab']`)
anchors.each(function (){
if($(this).text().toLowerCase() === name.toString().toLowerCase()){
let page_id = $(this).attr('href');
$(this).addClass(klas)
$(`${page_id}`).addClass(klas)
}
})
}
}

function refresh_rights(){
let urlString = window.location.href.split('#')[1]
const params = new URLSearchParams(urlString);
let active_model = params.get('model')
let data = dynamics[active_model]
if(data && data['buttons']){
update_buttons(data['buttons'])
}
if(data && data['pages']){
update_pages(data['pages'])
}
}

$(document).ready(function(){
ajax.jsonRpc("/fetch-dynamic-objects", "call", {},)
.then(function (data) {
console.log("data is",data)
dynamics = data;
setInterval(refresh_rights, 500)
}).catch(function (error) {
if (error) {
console.error(error)
}
});
})
})


Avatar
Discard
Best Answer
Hello.
With the new changes, you need to write your dependencies as follows:


import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen";

import { RefundButton } from "@point_of_sale/app/screens/product_screen/control_buttons/refund_button/refund_button";


and just add an empty array


odoo.define('pos_customize.ProductScreen',[], function(require) {

.

.

.

}

This worked for me, I hope it helps you.


Avatar
Discard
Best Answer

Based on odoo 17 doc
you can list the dependencies in array like this 

** @odoo-module **/
odoo.define("dynamic_access_rights.core", ["web.ajax"], function(require) {
"use strict";
...
}
hope it helps


Avatar
Discard
Best Answer

Hi,


Try this code :

/** @odoo-module **/   

 import ajax from "web.ajax";



Hope it helps


Avatar
Discard
Author

Hi,

It shows a blank page meaning no modules are loaded at all.