Skip to Content
Menu
This question has been flagged
2 Replies
2993 Rodiniai

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?




Portretas
Atmesti
Best Answer
  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.



Portretas
Atmesti
Best Answer

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

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
1
bal. 24
2076
2
saus. 24
2641
0
saus. 24
1662
1
rugs. 23
3083
1
liep. 23
2267