Skip to content

Commit

Permalink
[MIG] fieldservice_geoengine: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
peluko00 committed May 17, 2024
1 parent 5dee8cc commit 4138697
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
makepot: "true"
services:
postgres:
image: postgres:12.0
image: postgis/postgis:13-3.4
env:
POSTGRES_USER: odoo
POSTGRES_PASSWORD: odoo
Expand Down
14 changes: 8 additions & 6 deletions fieldservice_geoengine/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Field Service Geoengine
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:00cbfc11e03373e90815257e248560b520030ac74c71a26281dc3f5a96930b40
!! source digest: sha256:74438fc7ba6bb4441445c45d385f8490260b60a5d097618700e52d7b525b1f72
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -17,13 +17,13 @@ Field Service Geoengine
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Ffield--service-lightgray.png?logo=github
:target: https://github.com/OCA/field-service/tree/14.0/fieldservice_geoengine
:target: https://github.com/OCA/field-service/tree/16.0/fieldservice_geoengine
:alt: OCA/field-service
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/field-service-14-0/field-service-14-0-fieldservice_geoengine
:target: https://translation.odoo-community.org/projects/field-service-16-0/field-service-16-0-fieldservice_geoengine
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/field-service&target_branch=14.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/field-service&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -83,7 +83,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/field-service/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/field-service/issues/new?body=module:%20fieldservice_geoengine%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/field-service/issues/new?body=module:%20fieldservice_geoengine%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -109,6 +109,8 @@ Contributors
* Jevin Dement <jdement@opensourceintegrators.com>
* Murtuza Saleh <murtuza.saleh@serpentcs.com>
* Sebastiano Picchi <sebastiano.picchi@pytech.it>
* [APSL-Nagarro](https://apsl.tech):
* Antoni Marroig <amarroig@apsl.net>

Other credits
~~~~~~~~~~~~~
Expand Down Expand Up @@ -141,6 +143,6 @@ Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-wolfhall| |maintainer-max3903|

This module is part of the `OCA/field-service <https://github.com/OCA/field-service/tree/14.0/fieldservice_geoengine>`_ project on GitHub.
This module is part of the `OCA/field-service <https://github.com/OCA/field-service/tree/16.0/fieldservice_geoengine>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
7 changes: 6 additions & 1 deletion fieldservice_geoengine/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "Field Service Geoengine",
"summary": "Display Field Service locations on a map with Open Street Map",
"license": "AGPL-3",
"version": "14.0.1.2.2",
"version": "16.0.1.0.0",
"category": "Field Service",
"author": "Open Source Integrators, Odoo Community Association (OCA), Pytech SRL",
"website": "https://github.com/OCA/field-service",
Expand All @@ -17,6 +17,11 @@
"views/fsm_team.xml",
"views/fsm_order.xml",
],
"assets": {
"web.assets_backend": [
"fieldservice_geoengine/static/src/js/**",
]
},
"development_status": "Beta",
"maintainers": ["wolfhall", "max3903"],
}
1 change: 1 addition & 0 deletions fieldservice_geoengine/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

from . import fsm_location
from . import fsm_order
from . import vector_layer
2 changes: 1 addition & 1 deletion fieldservice_geoengine/models/fsm_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class FSMLocation(models.Model):
def create(self, vals):
res = super(FSMLocation, self).create(vals)
if not res.partner_latitude or not res.partner_longitude:
res.geo_localize()
res.with_context(force_geo_localize=True).geo_localize()
return res

def geo_localize(self):
Expand Down
33 changes: 33 additions & 0 deletions fieldservice_geoengine/models/vector_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2011-2012 Nicolas Bessi (Camptocamp SA)
# Copyright 2016 Yannick Payot (Camptocamp SA)
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, models
from odoo.exceptions import ValidationError

NUMBER_ATT = ["float", "integer", "integer_big"]


class GeoVectorLayer(models.Model):
_inherit = "geoengine.vector.layer"

@api.constrains("geo_repr", "attribute_field_id")
def _check_geo_repr(self):
for rec in self:
if (
rec.attribute_field_id
and rec.attribute_field_id.ttype not in NUMBER_ATT
and rec.model_id.name not in ["fsm.order", "fsm.location"]
and rec.geo_field_id.model not in ["fsm.order", "fsm.location"]
):
if (
rec.geo_repr == "colored"
and rec.classification != "unique"
or rec.geo_repr == "proportion"
):
raise ValidationError(

Check warning on line 29 in fieldservice_geoengine/models/vector_layer.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_geoengine/models/vector_layer.py#L29

Added line #L29 was not covered by tests
_(
"You need to select a numeric field",
)
)
2 changes: 2 additions & 0 deletions fieldservice_geoengine/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
* Jevin Dement <jdement@opensourceintegrators.com>
* Murtuza Saleh <murtuza.saleh@serpentcs.com>
* Sebastiano Picchi <sebastiano.picchi@pytech.it>
* [APSL-Nagarro](https://apsl.tech):
* Antoni Marroig <amarroig@apsl.net>
10 changes: 6 additions & 4 deletions fieldservice_geoengine/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ <h1 class="title">Field Service Geoengine</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:00cbfc11e03373e90815257e248560b520030ac74c71a26281dc3f5a96930b40
!! source digest: sha256:74438fc7ba6bb4441445c45d385f8490260b60a5d097618700e52d7b525b1f72
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/field-service/tree/14.0/fieldservice_geoengine"><img alt="OCA/field-service" src="https://img.shields.io/badge/github-OCA%2Ffield--service-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/field-service-14-0/field-service-14-0-fieldservice_geoengine"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/field-service&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/field-service/tree/16.0/fieldservice_geoengine"><img alt="OCA/field-service" src="https://img.shields.io/badge/github-OCA%2Ffield--service-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/field-service-16-0/field-service-16-0-fieldservice_geoengine"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/field-service&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module displays map views on the order and location using the GeoEngine module and PostGIS.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand Down Expand Up @@ -432,7 +432,7 @@ <h1><a class="toc-backref" href="#toc-entry-5">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/field-service/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/field-service/issues/new?body=module:%20fieldservice_geoengine%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/field-service/issues/new?body=module:%20fieldservice_geoengine%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -463,6 +463,8 @@ <h2><a class="toc-backref" href="#toc-entry-8">Contributors</a></h2>
</li>
<li>Murtuza Saleh &lt;<a class="reference external" href="mailto:murtuza.saleh&#64;serpentcs.com">murtuza.saleh&#64;serpentcs.com</a>&gt;</li>
<li>Sebastiano Picchi &lt;<a class="reference external" href="mailto:sebastiano.picchi&#64;pytech.it">sebastiano.picchi&#64;pytech.it</a>&gt;</li>
<li>[APSL-Nagarro](<a class="reference external" href="https://apsl.tech">https://apsl.tech</a>):
* Antoni Marroig &lt;<a class="reference external" href="mailto:amarroig&#64;apsl.net">amarroig&#64;apsl.net</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand All @@ -481,7 +483,7 @@ <h2><a class="toc-backref" href="#toc-entry-10">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/wolfhall"><img alt="wolfhall" src="https://github.com/wolfhall.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/max3903"><img alt="max3903" src="https://github.com/max3903.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/field-service/tree/14.0/fieldservice_geoengine">OCA/field-service</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/field-service/tree/16.0/fieldservice_geoengine">OCA/field-service</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/** @odoo-module */

/**
* Copyright 2024 APSL-Nagarro
*/

/* global chroma, geostats */

import {GeoengineRenderer} from "@base_geoengine/js/views/geoengine/geoengine_renderer/geoengine_renderer.esm";
import {patch} from "@web/core/utils/patch";

/* CONSTANTS */
const DEFAULT_BEGIN_COLOR = "#FFFFFF";
const DEFAULT_END_COLOR = "#000000";
const LEGEND_MAX_ITEMS = 10;
const DEFAULT_NUM_CLASSES = 5;

patch(GeoengineRenderer.prototype, "geoengine_renderer_view_patch", {
styleVectorLayerColored(cfg, data) {
var indicator = cfg.attribute_field_id[1];
var values = this.extractLayerValues(cfg, data);
var nb_class = cfg.nb_class || DEFAULT_NUM_CLASSES;
var opacity = cfg.layer_opacity;
var begin_color_hex = cfg.begin_color || DEFAULT_BEGIN_COLOR;
var end_color_hex = cfg.end_color || DEFAULT_END_COLOR;
var begin_color = chroma(begin_color_hex).alpha(opacity).css();
var end_color = chroma(end_color_hex).alpha(opacity).css();
// Function that maps numeric values to a color palette.
// This scale function is only used when geo_repr is basic
var scale = chroma.scale([begin_color, end_color]);
var serie = new geostats(values);
var vals = null;
switch (cfg.classification) {
case "unique":
case "custom":
vals = serie.getClassUniqueValues();
// "RdYlBu" is a set of colors
scale = chroma.scale("RdYlBu").domain([0, vals.length], vals.length);
break;
case "quantile":
serie.getClassQuantile(nb_class);
vals = serie.getRanges();
scale = scale.domain([0, vals.length], vals.length);
break;
case "interval":
serie.getClassEqInterval(nb_class);
vals = serie.getRanges();
scale = scale.domain([0, vals.length], vals.length);
break;
}
let colors = [];
if (cfg.classification === "custom") {
colors = vals
.filter((val) => val)
.map((val) => chroma(val).alpha(opacity).css());
} else {
colors = scale
.colors(vals.length)
.map((color) => chroma(color).alpha(opacity).css());
}
const styles_map = this.createStylesWithColors(colors);
let legend = null;
if (vals.length <= LEGEND_MAX_ITEMS) {
legend = serie.getHtmlLegend(colors, cfg.name, 1);
for (let i = 0; i < data.length; i++) {
legend = legend.replace(
data[i]._values[cfg.attribute_field_id[1]],
data[i]._values.stage_name
);
}
}
return {
style: (feature) => {
const value = feature.get("attributes")[indicator];
const color_idx = this.getClass(value, vals);
var label_text = feature.values_.attributes.label;
if (label_text === false) {
label_text = "";
} else if (label_text !== "") {
label_text = feature.values_.attributes.stage_name;
}
styles_map[colors[color_idx]][0].text_.text_ = label_text.toString();
return styles_map[colors[color_idx]];
},
legend,
};
},
async onLayerChanged(vector, layer) {
layer.setSource(null);
const element = document.getElementById(`legend-${vector.resId}`);
if (element !== null) {
element.remove();
}
if (vector.model) {
this.cfg_models.push(vector.model);
const fields_to_read = [vector.geo_field_id[1]];
if (vector.attribute_field_id) {
fields_to_read.push(vector.attribute_field_id[1]);
}
const data = await this.getModelData(vector, fields_to_read);
this.styleVectorLayerAndLegend(vector, data, layer);
this.useRelatedModel(vector, layer, data);
} else {
const data = [];
for (const record of this.props.data.records) {
if (
vector.attribute_field_id[1] === "custom_color" &&
typeof record.data[vector.attribute_field_id[1]] === "string"
) {
record.data[vector.attribute_field_id[1]] = parseInt(
record.data[vector.attribute_field_id[1]].split("#")[1],
16
);
}
data.push(record);
}
this.styleVectorLayerAndLegend(vector, data, layer);
this.addSourceToLayer(data, vector, layer);
}
},
styleVectorLayerAndLegend(cfg, data, lv) {
const aux = [];
for (var i = 0; i < data.length; i++) {
if (
cfg.attribute_field_id[1] === "custom_color" &&
typeof data[i]._values[cfg.attribute_field_id[1]] === "string"
) {
data[i]._values[cfg.attribute_field_id[1]] = parseInt(
data[i]._values[cfg.attribute_field_id[1]].split("#")[1],
16
);
}
aux.push(data[i]);
}
const styleInfo = this.styleVectorLayer(cfg, aux);
this.initLegend(styleInfo, cfg);
lv.setStyle(styleInfo.style);
},
});
8 changes: 4 additions & 4 deletions fieldservice_geoengine/tests/test_fsm_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields
from odoo.tests.common import SavepointCase
from odoo.tests.common import TransactionCase


class TestFsmLocation(SavepointCase):
class TestFsmLocation(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down Expand Up @@ -60,10 +60,10 @@ def test_fsm_location_creation(self):
self.assertTrue(test_location_1.partner_latitude)
self.assertTrue(test_location_1.partner_longitude)
self.assertAlmostEqual(
test_location_1.partner_latitude, 50.629980, delta=self.delta
test_location_1.partner_latitude, 50.629980, delta=0.0002
)
self.assertAlmostEqual(
test_location_1.partner_longitude, 4.863370, delta=self.delta
test_location_1.partner_longitude, 4.863370, delta=0.00012
)
# direct creation and same exit data
partner_latitude = 1.0
Expand Down
Loading

0 comments on commit 4138697

Please sign in to comment.