Se rendre au contenu
Menu
Cette question a été signalée
2 Réponses
4831 Vues

Hello,
I am getting this error in this javascript desipite importing the necessary modules.
What could be the issue here?

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

  • web.core

The following modules could not be loaded because they have unmet dependencies, this is a secondary error which is likely caused by one of the above problems:

  • @dynamic_access_rights/js/crawler


Here is my code:

/** @odoo-module **/

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

odoo.define("dynamic_access_rights.core", (require) => {
"use strict";

const { Component } = owl;
const { xml } = owl.tags;
const { whenReady } = owl.utils;

//const { jsonRpc } = require('web.core'); // Ensure web.core is imported



class DynamicAccessRights extends Component {
constructor() {
super(...arguments);
this.dynamics = null;
}

async willStart() {
const data = await jsonRpc("/fetch-dynamic-objects", "call", {});
this.dynamics = data;
}

updateButtons(targetButtons) {
for (const button of targetButtons) {
const klas = `dynamics-${button.restriction}`;
const name = button.name;
const buttons1 = this.el.querySelectorAll(`button[name='${name}']`);
const buttons2 = this.el.querySelectorAll(`.${name}`);
buttons1.forEach((button) => button.classList.add(klas));
buttons2.forEach((button) => button.classList.add(klas));
}
}

updatePages(targetPages) {
for (const page of targetPages) {
const klas = `dynamics-${page.restriction}`;
const name = page.name;
const anchors = this.el.querySelectorAll("a[role='tab']");
anchors.forEach((anchor) => {
if (anchor.textContent.toLowerCase() === name.toString().toLowerCase()) {
const pageId = anchor.getAttribute('href');
anchor.classList.add(klas);
this.el.querySelector(`${pageId}`).classList.add(klas);
}
});
}
}

refreshRights() {
const urlString = window.location.href.split('#')[1];
const params = new URLSearchParams(urlString);
const activeModel = params.get('model');
const data = this.dynamics[activeModel];
if (data && data['buttons']) {
this.updateButtons(data['buttons']);
}
if (data && data['pages']) {
this.updatePages(data['pages']);
}
}

mounted() {
this.intervalId = setInterval(this.refreshRights.bind(this), 500);
}

willUnmount() {
clearInterval(this.intervalId);
}
}

DynamicAccessRights.template = xml`

`;

whenReady(DynamicAccessRights);

return DynamicAccessRights;
});


Avatar
Ignorer
Auteur

Hi, @Cybrosys your solution eliminated one of the errors but I am getting this error now.
I have updated the code above with your solution.

Kindly advise:

Uncaught Error: Error while loading "@dynamic_access_rights/js/crawler":
Error: Dependencies should be defined by an array: (require)=>{"use strict";const{Component,hooks}=owl;const{useService}=owl.hooks;let dynamics=null;class DynamicAccessRights extends Component{constructor(){super(...arguments);this.dynamics=useService("dynamicAccessRights");}
async willStart(){const data=await jsonRpc("/fetch-dynamic-objects","call",{});this.dynamics=data;}
updateButtons(targetButtons){for(const button of targetButtons){const klas=`dynamics-${button.restriction}`;const name=button.name;const buttons1=this.el.querySelectorAll(`button[name='${name}']`);const buttons2=this.el.querySelectorAll(`.${name}`);buttons1.forEach((button)=>button.classList.add(klas));buttons2.forEach((button)=>button.classList.add(klas));}}
updatePages(targetPages){for(const page of targetPages){const klas=`dynamics-${page.restriction}`;const name=page.name;const anchors=this.el.querySelectorAll("a[role='tab']");anchors.forEach((anchor)=>{if(anchor.textContent.toLowerCase()===name.toString().toLowerCase()){const pageId=anchor.getAttribute('href');anchor.classList.add(klas);this.el.querySelector(`${pageId}`).classList.add(klas);}});}}
refreshRights(){const urlString=window.location.href.split('#')[1];const params=new URLSearchParams(urlString);const activeModel=params.get('model');const data=this.dynamics[activeModel];if(data&&data['buttons']){this.updateButtons(data['buttons']);}
if(data&&data['pages']){this.updatePages(data['pages']);}}
mounted(){this.intervalId=setInterval(this.refreshRights.bind(this),500);}
willUnmount(){clearInterval(this.intervalId);}}
DynamicAccessRights.template=owl.tags.xml`<div></div>`;hooks.whenReady(DynamicAccessRights);return DynamicAccessRights;}

Meilleure réponse

Hi,

In Odoo 17 the OWL js method is mostly using in the JS codes. Currently You are using the Back bone method. So please try to migrate the code to OWL method and try it again
You can refer the below blog to get an idea on OWL:
An overview of owl component in odoo


Hope it helps

Avatar
Ignorer
Publications associées Réponses Vues Activité
4
mai 25
6972
3
avr. 24
4460
1
janv. 24
2808
0
avr. 25
127
0
déc. 24
622