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?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- 客戶關係
- e-Commerce
- 會計
- 庫存
- PoS
- Project
- MRP
此問題已被標幟
Create a JavaScript file (e.g., map_model_ext.js) within your custom module.
In the JavaScript file, import the required dependencies and define your extended class MapModelExt.
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.
- 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
|
2088 | ||
|
2
1月 24
|
2653 | ||
|
0
1月 24
|
1668 | ||
|
1
9月 23
|
3090 | ||
|
1
7月 23
|
2272 |