Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
4834 Tampilan

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
Buang
Penulis

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

Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
4
Mei 25
6986
3
Apr 24
4465
1
Jan 24
2816
0
Apr 25
131
0
Des 24
625