Is it possible to add geoengine with an SQL view model?
lizhi2013 opened this issue · 9 comments
my model is like this :
sql="""
CREATE OR REPLACE VIEW xxxxx AS (
XXXX
)
"""
class view_xxxx(models.Model):
_name = 'view_xxxx'
_description = u'view_xxxx'
_auto = False
....
def init(self):
tools.drop_view_if_exists(self._cr, 'xxxxx')
self._cr.execute(sql)
@api.model
def _migrate_update(self):
tools.drop_view_if_exists(self._cr, 'xxxxx')
self._cr.execute(sql)
....
the errror code show ,can not add add the properties to a databse view
I can query all the properties from an geo_model.GeoModel object in the database view
@lizhi2013 do you have a full stack trace? Which version of Odoo are you using?
I never tried to create an SQL view with geoengine, so I don't know if it ever worked. But we definitely want that to be possible.
i only can do in code and sql like this ....
sql="""
CREATE OR REPLACE VIEW .... AS (
select .....
b.lon,
b.lat,
b.maplonlat,
b.maplon,
b.maplat,
b.geo_point,
b.geo_multiline,
....
)
"""
#gps info this info is from and geo_model.GeoModel
lon = fields.Float(string='Longitude',digits=(20,15), )
lat = fields.Float(string='Latitude',digits=(20,15),)
maplonlat=fields.Char(string="Map point Longitude Latitude",)
maplon = fields.Float('MapLongitude',digits=(20,15) )
maplat = fields.Float('MapLatitude',digits=(20,15))
....
but I can not set then to an geo_model.GeoModel object
i can full stack trace now
I read the code, I understand the principle of geoengine a bit, geo_model.GeoModel will inherit the original model, and then automatically add some attributes to the principle object, so it will necessarily involve the modification of the model database table, and the database view It ca n’t be modified, so it will be wrong, so I understand that my needs should be a requirement. Can I achieve the function of providing geo without changing the original object?
In version 10.0 the GeoModel inherits in a python way from models.BaseModel
[1] which means you should be able to use is the same way as models.Model
with additional methods related to postgis. [2]
If I understand what you are trying to do is to define geo_point
and geo_multiline`
Reading from your code what you want is a geo_field. [3] Then, it means your SQL query needs to transform your long and lat to postgis geometries [4].
On the model in your python file of your SQL view you need to declare:
from odoo.addons.base_geoengine import fields as geo_fields
# ...
geo_point = geo_fields.GeoPoint('Coordinate')
geo_multline = geo_fields.GeoLine('Multiline')
Then what you put in your SQL query can be a select from an other model geo_field or you will need to change the type using postgis functions.
If you didn't already, I suggest you to refer to the demo module to see how to use it:
https://github.com/OCA/geospatial/tree/10.0/base_geoengine_demo
[1] https://github.com/OCA/geospatial/blob/10.0/base_geoengine/geo_model.py#L15
[2] https://github.com/odoo/odoo/blob/10.0/odoo/models.py#L5665
[3] http://oca.github.io/geospatial/api_doc.html#module-base_geoengine.geo_field
[4] https://postgis.net/docs/ST_GeomFromText.html
thank