콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
4829 화면

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


아바타
취소
작성자

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

베스트 답변

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

아바타
취소
관련 게시물 답글 화면 활동
4
5월 25
6965
3
4월 24
4457
1
1월 24
2804
0
4월 25
123
0
12월 24
620