diff --git a/pos_customer_screen_partner_location_google_map/README.rst b/pos_customer_screen_partner_location_google_map/README.rst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pos_customer_screen_partner_location_google_map/__init__.py b/pos_customer_screen_partner_location_google_map/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pos_customer_screen_partner_location_google_map/__manifest__.py b/pos_customer_screen_partner_location_google_map/__manifest__.py new file mode 100644 index 0000000000..76b91b311a --- /dev/null +++ b/pos_customer_screen_partner_location_google_map/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright (C) 2024 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "POS Customer Screen Partner Location Google Map", + "version": "16.0.1.0.0", + "category": "Point Of Sale", + "summary": "Select partner location in POS on the customer screen Google map", + "author": "Cetmix, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/pos", + "license": "AGPL-3", + "depends": [ + "pos_customer_screen_partner_location", + "pos_partner_location_google_map", + ], + "data": [], + "assets": { + "web.assets_frontend": [ + "pos_customer_screen_partner_location_google_map/static/src/portal/*.js", + ] + }, + "installable": True, +} diff --git a/pos_customer_screen_partner_location_google_map/static/src/portal/customer_screen_map.js b/pos_customer_screen_partner_location_google_map/static/src/portal/customer_screen_map.js new file mode 100644 index 0000000000..dfe59e75ff --- /dev/null +++ b/pos_customer_screen_partner_location_google_map/static/src/portal/customer_screen_map.js @@ -0,0 +1,119 @@ +odoo.define( + "pos_customer_screen_partner_location_google_map.customer_screen_map", + function (require) { + "use strict"; + + const publicWidget = require("web.public.widget"); + const {loadJS} = require("@web/core/assets"); + + /* eslint no-undef: "warn"*/ + publicWidget.registry.CustomerScreenMap.include({ + onHandleMap() { + return this._rpc({ + model: "pos.config", + method: "read", + args: [ + [this.posConfigId], + ["geolocalize_tech_name", "googlemap_api_key"], + ], + }).then((response) => { + if (response.length > 0) { + const data = response[0]; + this.provider = data.geolocalize_tech_name; + if (this.provider === "googlemap") { + loadJS( + `https://maps.googleapis.com/maps/api/js?key=${data.googlemap_api_key}&libraries=places` + ).then(() => { + this.googleMapConfigure(); + }); + } + } + }); + }, + + googleMapConfigure() { + // Default latLng + // Config + this.geocoder = new google.maps.Geocoder(); + const latLng = new google.maps.LatLng(this.lat, this.lng); + const mapOptions = { + zoom: 12, + center: latLng, + }; + // Show Map + this.map = new google.maps.Map(this.mapContainerRef, mapOptions); + + if (this.lat && this.lng) { + this.setAddressByLatLng(this.lat, this.lng); + } else { + this.setAddressByLocation(this.contact_address); + } + + this.marker = new google.maps.Marker({ + position: latLng, + map: this.map, + draggable: true, + }); + + this.addrInput.value = this.contact_address; + + this.map.addListener("click", (event) => { + const lat = event.latLng.lat(); + const lng = event.latLng.lng(); + this.updateMarker(lat, lng); + this.setAddressByLatLng(lat, lng); + }); + }, + + setAddressByLatLng(lat, lng) { + if (lat && lng) { + const latLng = new google.maps.LatLng(lat, lng); + this.geocoder.geocode({location: latLng}, (results, status) => { + if (status === google.maps.GeocoderStatus.OK) { + this.getFormattedAddress(results[0].place_id).then(() => { + this.addrInput.value = results[0].formatted_address; + }); + } + }); + } + }, + + updateMarker(lat, lng) { + this._super(...arguments); + if (this.provider === "googlemap") { + const latLng = new google.maps.LatLng(lat, lng); + this.map.setCenter(latLng); + this.marker.setPosition(latLng); + google.maps.event.trigger(this.map, "resize"); + } + }, + + setAddressByLocation(address) { + if (address && this.provider === "googlemap") { + this.geocoder.geocode({address: address}, (results, status) => { + if (status === google.maps.GeocoderStatus.OK) { + this.lat = results[0].geometry.location.lat(); + this.lng = results[0].geometry.location.lng(); + this.getFormattedAddress(results[0].place_id).then(() => { + this.addrInput.value = results[0].formatted_address; + this.updateMarker(this.lat, this.lng); + }); + } + }); + } else { + this._super(...arguments); + } + }, + + getFormattedAddress(place_id) { + return this._rpc({ + model: "base.geocoder", + method: "prepare_geo_address_googlemap", + args: [place_id], + }).then((resp) => { + this.address = resp; + }); + }, + }); + } +); diff --git a/setup/pos_customer_screen_partner_location_google_map/odoo/addons/pos_customer_screen_partner_location_google_map b/setup/pos_customer_screen_partner_location_google_map/odoo/addons/pos_customer_screen_partner_location_google_map new file mode 120000 index 0000000000..404c0e9c06 --- /dev/null +++ b/setup/pos_customer_screen_partner_location_google_map/odoo/addons/pos_customer_screen_partner_location_google_map @@ -0,0 +1 @@ +../../../../pos_customer_screen_partner_location_google_map \ No newline at end of file diff --git a/setup/pos_customer_screen_partner_location_google_map/setup.py b/setup/pos_customer_screen_partner_location_google_map/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/pos_customer_screen_partner_location_google_map/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)