Skip to content

Commit

Permalink
[MIG] base_geoengine: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
reichie020212 committed Jan 31, 2024
1 parent ca91f65 commit 62abfac
Show file tree
Hide file tree
Showing 30 changed files with 201 additions and 103 deletions.
2 changes: 1 addition & 1 deletion base_geoengine/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Geospatial support for Odoo",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"category": "GeoBI",
"author": "Camptocamp,ACSONE SA/NV,Odoo Community Association (OCA)",
"license": "AGPL-3",
Expand Down
5 changes: 2 additions & 3 deletions base_geoengine/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from odoo.osv import expression
from odoo.osv.expression import TERM_OPERATORS
from odoo.tools import Query
from odoo.tools import SQL, Query

from .fields import GeoField
from .geo_operators import GeoOperator
Expand Down Expand Up @@ -35,7 +35,6 @@ def __leaf_to_sql(self, leaf, model, alias):
geo_operators into the Odoo search method.
"""
left, operator, right = leaf

if isinstance(leaf, (list, tuple)):
current_field = model._fields.get(left)
current_operator = GeoOperator(current_field)
Expand Down Expand Up @@ -89,7 +88,7 @@ def __leaf_to_sql(self, leaf, model, alias):
query = get_geo_func(
current_operator, operator, left, right, params, model._table
)
return query, params
return SQL(query, *params)
return original__leaf_to_sql(self, leaf=leaf, model=model, alias=alias)


Expand Down
3 changes: 2 additions & 1 deletion base_geoengine/geo_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
_schema = logging.getLogger("odoo.schema")


def init_postgis(cr):
def init_postgis(env):
"""Initialize postgis
Add PostGIS support to the database. PostGIS is a spatial database
extender for PostgreSQL object-relational database. It adds support for
geographic objects allowing location queries to be run in SQL.
"""
cr = env.cr
cr.execute(
"""
SELECT
Expand Down
5 changes: 5 additions & 0 deletions base_geoengine/models/ir_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ class IrUIView(models.Model):
)
default_zoom = fields.Integer("Default map zoom")
restricted_extent = fields.Char("Restricted map extent")

def _is_qweb_based_view(self, view_type):
if view_type == "geoengine":
return True
return super()._is_qweb_based_view(view_type)
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
import {addFieldDependencies} from "@web/views/utils";
import {Field} from "@web/views/fields/field";
import {Widget} from "@web/views/widgets/widget";
import {XMLParser} from "@web/core/utils/xml";
import {parseXML} from "@web/core/utils/xml";
import {_lt} from "@web/core/l10n/translation";

export const INFO_BOX_ATTRIBUTE = "info_box";

class XMLParser {
parse() {}
visitXML(xml, callback) {}
}

export class GeoengineArchParser extends XMLParser {
/**
* Allow you to browse and process the xml template of the geoengine view.
Expand All @@ -21,7 +26,7 @@ export class GeoengineArchParser extends XMLParser {
* @returns {Object}
*/
parse(arch, models, modelName) {
const xmlDoc = this.parseXML(arch);
const xmlDoc = parseXML(arch);
const templateDocs = {};
const fieldNodes = {};
const jsClass = xmlDoc.getAttribute("js_class");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import {Layout} from "@web/search/layout";
import {useModel} from "@web/views/model";
import {useModel} from "@web/model/model";
import {usePager} from "@web/search/pager_hook";
import {useOwnedDialogs, useService} from "@web/core/utils/hooks";
import {FormViewDialog} from "@web/views/view_dialogs/form_view_dialog";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<templates>
<t t-name="base_geoengine.GeoengineController" owl="1">
<t t-name="base_geoengine.GeoengineController">
<Layout display="props.display" className="'h-100'">
<t t-set-slot="layout-buttons">
<t t-if="model.root.editedRecord">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<templates xml:space="preserve">
<t t-name="base_geoengine_GeoengineRecord" owl="1">
<t t-name="base_geoengine_GeoengineRecord">
<div>
<t t-call="{{ templates[this.constructor.INFO_BOX_ATTRIBUTE] }}" />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {rasterLayersStore} from "../../../raster_layers_store.esm";
import {vectorLayersStore} from "../../../vector_layers_store.esm";
import {useService} from "@web/core/utils/hooks";
import {registry} from "@web/core/registry";
import {RelationalModel} from "@web/views/relational_model";
import {RelationalModel} from "@web/model/relational_model/relational_model";
import {evaluateExpr} from "@web/core/py_js/py";
import {
Component,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<templates xml:space="preserve">
<t t-name="base_geoengine.GeoengineRenderer" owl="1">
<t t-name="base_geoengine.GeoengineRenderer">
<div class="d-flex view w-100">
<LayersPanel model="props.data.resModel" vectorModel="vectorModel.root" />
<div class="map_container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {GeoengineController} from "./geoengine_controller/geoengine_controller.e
import {GeoengineRenderer} from "./geoengine_renderer/geoengine_renderer.esm";
import {GeoengineArchParser} from "./geoengine_arch_parser.esm";
import {GeoengineCompiler} from "./geoengine_compiler.esm";
import {RelationalModel} from "@web/views/relational_model";
import {RelationalModel} from "@web/model/relational_model/relational_model";
import {registry} from "@web/core/registry";

export const geoengineView = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<templates>
<t t-name="base_geoengine.LayersPanel" owl="1">
<t t-name="base_geoengine.LayersPanel">
<div
class="menu border-end"
t-attf-class="{{ state.isFolded ? 'o_layer_panel_fold ' : 'o_layer_panel bg-view' }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<templates>
<t t-name="base_geoengine.RecordsPanel" owl="1">
<t t-name="base_geoengine.RecordsPanel">
<div
class="menu border-end scroller"
t-attf-class="{{ state.isFolded ? 'o_layer_panel_fold ' : 'o_layer_panel bg-view' }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<templates>
<t t-name="base_geoengine.SearchBarRecords" owl="1">
<t t-name="base_geoengine.SearchBarRecords">
<div class="o_cp_searchview d-flex flex-grow-1" role="search">
<div
class="o_searchview pb-1 align-self-center border-bottom flex-grow-1"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/** @odoo-module **/

import {registry} from "@web/core/registry";

import {Component} from "@odoo/owl";
const parsers = registry.category("parsers");

export class DomainSelectorFieldInput extends Component {
parseValue(value) {
const parser = parsers.get(this.props.field.type, (value) => value);
try {
return parser(value);
} catch (_) {
return value;
}
}

onChange(ev) {
this.props.update({value: this.parseValue(ev.target.value)});
}
}
DomainSelectorFieldInput.template = "base_geoengine.DomainSelectorFieldInput";
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="base_geoengine.DomainSelectorFieldInput">
<input
type="text"
class="o_input o_domain_leaf_value_input"
t-att-value="props.value"
t-on-change="onChange"
/>
</t>

</templates>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="base_geoengine.DomainSelectorFieldInputForActiveIds" owl="1">
<t t-name="base_geoengine.DomainSelectorFieldInputForActiveIds">
<input
type="text"
class="o_input o_domain_leaf_value_input"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** @odoo-module **/

import {Component, useRef} from "@odoo/owl";

export class DomainSelectorFieldInputWithTags extends Component {
setup() {
this.inputRef = useRef("input");
}

removeTag(tagIndex) {
const value = [...this.props.value];
value.splice(tagIndex, 1);
this.props.update({value});
}
addTag(value) {
this.props.update({value: this.props.value.concat(value)});
}

onBtnClick() {
const value = this.inputRef.el.value;
this.inputRef.el.value = "";
this.addTag(value);
}
}
DomainSelectorFieldInputWithTags.template =
"base_geoengine.DomainSelectorFieldInputWithTags";
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="base_geoengine.DomainSelectorFieldInputWithTags">
<div class="o_ds_value_cell">
<div class="o_domain_leaf_value_input">
<t t-foreach="props.value" t-as="tag" t-key="tag_index">
<span class="badge rounded-pill">
<t t-esc="tag" /> <i
class="o_domain_leaf_value_remove_tag_button fa fa-times"
role="img"
aria-label="Remove tag"
title="Remove tag"
t-on-click="() => this.removeTag(tag_index)"
/>
</span>
</t>
</div>
<div class="o_domain_leaf_value_tags">
<input
type="text"
class="o_input"
placeholder="Add new value"
t-ref="input"
/>
<button
class="btn btn-sm btn-primary fa fa-plus o_domain_leaf_value_add_tag_button"
aria-label="Add tag"
title="Add tag"
t-on-click="onBtnClick"
/>
</div>
</div>
</t>

</templates>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<templates xml:space="preserve">
<t t-name="base_geoengine.DomainSelectorGeoField" owl="1">
<t t-name="base_geoengine.DomainSelectorGeoField">
<div class="o_ds_value_cell">
<DomainSelectorGeoFieldInput t-props="props" />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
t-name="base_geoengine.DomainSelectorGeoFieldDialog"
t-inherit="web.DomainSelectorDialog"
t-inherit-mode="primary"
owl="1"
>
</t>
</templates>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="base_geoengine.DomainSelectorGeoFieldInput" owl="1">
<t t-name="base_geoengine.DomainSelectorGeoFieldInput">
<div class="d-flex align-items-center">
<ModelSelector
value="state.resModel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import {registry} from "@web/core/registry";
import {_lt} from "@web/core/l10n/translation";
import {DomainSelectorFieldInput} from "@web/core/domain_selector/fields/domain_selector_field_input";
import {DomainSelectorFieldInput} from "../domain_selector_field_input/domain_selector_field_input.esm";
import {DomainSelectorFieldInputForActiveIds} from "../domain_selector_field_input_for_active_ids/domain_selector_field_input_for_active_ids.esm";
import {DomainSelectorFieldInputWithTags} from "@web/core/domain_selector/fields/domain_selector_field_input_with_tags";
import {DomainSelectorFieldInputWithTags} from "../domain_selector_field_input_with_tags/domain_selector_field_input_with_tags.esm";
import {onDidChange} from "../domain_selector_operators.esm";

const dso = registry.category("domain_selector/operator");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="base_geoengine.DomainSelectorNumberFieldExtend" owl="1">
<t t-name="base_geoengine.DomainSelectorNumberFieldExtend">
<t t-if="props.operator.category === 'in'">
<DomainSelectorFieldInputWithTags t-props="props" />
</t>
Expand Down
Loading

0 comments on commit 62abfac

Please sign in to comment.