From b10e9a6486fbd8d57d97cd95ecc8976d86bcb8b4 Mon Sep 17 00:00:00 2001 From: "Murtuza Saleh(SerpentCS)" Date: Thu, 18 Apr 2019 23:39:12 +0530 Subject: [PATCH 01/64] [ADD][WIP][12.0] fieldservice_geoengine (#170) --- fieldservice_geoengine/__init__.py | 4 + fieldservice_geoengine/__manifest__.py | 25 ++++++ fieldservice_geoengine/models/__init__.py | 5 ++ fieldservice_geoengine/models/fsm_location.py | 57 ++++++++++++++ fieldservice_geoengine/models/fsm_order.py | 40 ++++++++++ fieldservice_geoengine/views/fsm_order.xml | 77 +++++++++++++++++++ fieldservice_geoengine/views/fsm_team.xml | 12 +++ 7 files changed, 220 insertions(+) create mode 100644 fieldservice_geoengine/__init__.py create mode 100644 fieldservice_geoengine/__manifest__.py create mode 100644 fieldservice_geoengine/models/__init__.py create mode 100644 fieldservice_geoengine/models/fsm_location.py create mode 100644 fieldservice_geoengine/models/fsm_order.py create mode 100644 fieldservice_geoengine/views/fsm_order.xml create mode 100644 fieldservice_geoengine/views/fsm_team.xml diff --git a/fieldservice_geoengine/__init__.py b/fieldservice_geoengine/__init__.py new file mode 100644 index 0000000000..631bd4893a --- /dev/null +++ b/fieldservice_geoengine/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2018 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/fieldservice_geoengine/__manifest__.py b/fieldservice_geoengine/__manifest__.py new file mode 100644 index 0000000000..6573e7ea28 --- /dev/null +++ b/fieldservice_geoengine/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright (C) 2018 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Field Service Geoengine', + 'summary': 'Extend field service functionality based on Geoengine', + 'version': '12.0.1.0.0', + 'category': 'Field Service', + 'author': 'Open Source Integrators, Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/field-service', + 'depends': [ + 'base_geoengine', + 'fieldservice', + ], + 'data': [ + 'views/fsm_order.xml', + 'views/fsm_team.xml' + ], + 'license': 'AGPL-3', + 'development_status': 'Beta', + 'maintainers': [ + 'wolfhall', + 'max3903', + ], +} diff --git a/fieldservice_geoengine/models/__init__.py b/fieldservice_geoengine/models/__init__.py new file mode 100644 index 0000000000..20026a1ba8 --- /dev/null +++ b/fieldservice_geoengine/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright (C) 2018 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import fsm_location +from . import fsm_order diff --git a/fieldservice_geoengine/models/fsm_location.py b/fieldservice_geoengine/models/fsm_location.py new file mode 100644 index 0000000000..f14aa139b7 --- /dev/null +++ b/fieldservice_geoengine/models/fsm_location.py @@ -0,0 +1,57 @@ +# Copyright (C) 2018 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + +from odoo.addons.base_geoengine import fields as geo_fields + + +class FSMLocation(models.Model): + _inherit = 'fsm.location' + + # Geometry Field + shape = fields.GeoPoint('Coordinate') + + @api.model + def create(self, vals): + vals.update({'fsm_location': True}) + res = super(FSMLocation, self).create(vals) + lat = self.partner_id.partner_latitude + lng = self.partner_id.partner_longitude + if lat == 0.0 and lng == 0.0: + res.geo_localize() + else: + point = geo_fields.GeoPoint.from_latlon(cr=self.env.cr, + latitude=lat, + longitude=lng) + self.shape = point + return res + + def geo_localize(self): + for loc in self: + if loc.partner_id: + loc.partner_id.geo_localize() + lat = loc.partner_latitude + lng = loc.partner_longitude + point = geo_fields.GeoPoint.from_latlon(cr=loc.env.cr, + latitude=lat, + longitude=lng) + loc.shape = point + + def _update_order_geometries(self): + for loc in self: + orders = loc.env['fsm.order'].search( + [('location_id', '=', loc.id)]) + for order in orders: + order.create_geometry() + + @api.multi + def write(self, vals): + res = super(FSMLocation, self).write(vals) + if ('partner_latitude' in vals) and ('partner_longitude' in vals): + self.shape = geo_fields.GeoPoint.from_latlon( + cr=self.env.cr, + latitude=vals['partner_latitude'], + longitude=vals['partner_longitude']) + self._update_order_geometries() + return res diff --git a/fieldservice_geoengine/models/fsm_order.py b/fieldservice_geoengine/models/fsm_order.py new file mode 100644 index 0000000000..c4d5d814ed --- /dev/null +++ b/fieldservice_geoengine/models/fsm_order.py @@ -0,0 +1,40 @@ +# Copyright (C) 2018 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + +from odoo.addons.base_geoengine import fields as geo_fields + + +class FSMOrder(models.Model): + _inherit = 'fsm.order' + + # Geometry Field + shape = fields.GeoPoint('Coordinate') + + @api.model + def create(self, vals): + res = super(FSMOrder, self).create(vals) + res.create_geometry() + return res + + @api.onchange('location_id') + def onchange_location_id(self): + res = super(FSMOrder, self).onchange_location_id() + if self.location_id: + self.create_geometry() + return res + + def create_geometry(self): + for order in self: + lat = order.location_id.partner_latitude + lng = order.location_id.partner_longitude + point = geo_fields.GeoPoint.from_latlon(cr=order.env.cr, + latitude=lat, + longitude=lng) + order.shape = point + + @api.multi + def geo_localize(self): + for order in self: + order.location_id.partner_id.geo_localize() diff --git a/fieldservice_geoengine/views/fsm_order.xml b/fieldservice_geoengine/views/fsm_order.xml new file mode 100644 index 0000000000..62a94e4a60 --- /dev/null +++ b/fieldservice_geoengine/views/fsm_order.xml @@ -0,0 +1,77 @@ + + + + + + fsm.order.form + fsm.order + + + + + +