Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
4813 Vizualizări

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;
});


Imagine profil
Abandonează
Autor

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;}

Cel mai bun răspuns

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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
4
mai 25
6946
3
apr. 24
4454
1
ian. 24
2799
0
apr. 25
112
0
dec. 24
615