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

I am trying to inherit transfer map view and for that I am inheriting enterprise addons web_map. I am not able to properly inherit js class MapModel.

/** @odoo-module **/
"use strict";

import { registry } from "@web/core/registry";
import { session } from "@web/session";
import { browser } from "@web/core/browser/browser";
import { KeepLast } from "@web/core/utils/concurrency";
import { MapModel } from "@web_map/map_view/map_model";

console.log(registry); // Class is coming in console

export class MapModelExt extends MapModel {
// add your custom code here
setup(params, { notification, http }) {
super.setup(params, options);
console.log("Hello from MyMapModel!");
this.notification = notification;
this.http = http;

this.metaData = {
...params,
mapBoxToken: session.map_box_token || "",
};

this.data = {
count: 0,
fetchingCoordinates: false,
groupByKey: false,
isGrouped: false,
numberOfLocatedRecords: 0,
partnerIds: [],
partners: [],
partnerToCache: [],
recordGroups: [],
records: [],
routes: [],
routingError: null,
shouldUpdatePosition: true,
useMapBoxAPI: !!this.metaData.mapBoxToken,
};

this.coordinateFetchingTimeoutHandle = undefined;
this.shouldFetchCoordinates = false;
this.keepLast = new KeepLast();
}


}

My extended code is not being loaded into odoo backend assets, only base code is running. Changes are not being reflected. What am I missing?




아바타
취소
베스트 답변
  1. Create a JavaScript file (e.g., map_model_ext.js) within your custom module.

  2. In the JavaScript file, import the required dependencies and define your extended class MapModelExt.

  3. Register your extended class in the Odoo registry using the registry object.

/** @odoo-module **/
import { registry } from "@web/core/registry";
import { session } from "@web/session";
import { KeepLast } from "@web/core/utils/concurrency";
import { MapModel } from "@web_map/map_view/map_model";

export class MapModelExt extends MapModel {
// Add your custom code here
setup(params, options) {
super.setup(params, options);
console.log("Hello from MyMapModel!");
// Your custom setup logic here
}
}

registry.category("models").add("map_model_ext", MapModelExt);

Make sure to include the JavaScript file in the manifest file (__manifest__.py) of your custom module. Add the JavaScript file to the assets section.

{
"name": "Your Module",
"version": "1.0",
"depends": ["web_map"],
  "assets": {
"web.assets_frontend": ["path_to_your_js_file"],
"web.assets_backend": ["path_to_your_js_file"]
}
}

Replace "path_to_your_js_file" with the actual path to your JavaScript file, relative to the module directory.

  1. After making these changes, restart your Odoo server and clear your browser's cache to ensure that the updated JavaScript code is loaded.



아바타
취소
베스트 답변

Hi,

If you want to update the "map_model" in order to add new functions or update existing ones, you can try patching the "map_model" component. You can follow a step-by-step guide in the blog post "https://www.cybrosys.com/blog/how-to-patch-existing-owl-component-in-odoo-16". This guide will provide you with detailed instructions on how to patch the OWL model.
Alternatively, if you prefer to create a new "model" that incorporates all the existing functions from the current "map_model", extend it with your desired changes. and add the newly created class in "web/core/registry"

Hope it helps

아바타
취소
관련 게시물 답글 화면 활동
1
4월 24
2085
2
1월 24
2650
0
1월 24
1665
1
9월 23
3087
1
7월 23
2271