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:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
1
thg 4 24
|
2095 | ||
|
2
thg 1 24
|
2657 | ||
|
0
thg 1 24
|
1671 | ||
|
1
thg 9 23
|
3092 | ||
|
1
thg 7 23
|
2273 |