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
أبريل 24
|
2076 | ||
|
2
يناير 24
|
2639 | ||
|
0
يناير 24
|
1662 | ||
|
1
سبتمبر 23
|
3082 | ||
|
1
يوليو 23
|
2265 |