From e9705b31491c82350d9c8f8c635b4c25380edf9a Mon Sep 17 00:00:00 2001 From: Maksim Shurupov Date: Sat, 18 May 2024 21:55:05 +0400 Subject: [PATCH] [ADD] pos_customer_screen_partner_location_google_map: Module added. --- .../README.rst | 80 ++++ .../__init__.py | 0 .../__manifest__.py | 24 + .../readme/CONTRIBUTORS.rst | 5 + .../readme/DESCRIPTION.rst | 1 + .../static/description/index.html | 424 ++++++++++++++++++ .../static/src/portal/customer_screen_map.js | 119 +++++ ...ustomer_screen_partner_location_google_map | 1 + .../setup.py | 6 + 9 files changed, 660 insertions(+) create mode 100644 pos_customer_screen_partner_location_google_map/README.rst create mode 100644 pos_customer_screen_partner_location_google_map/__init__.py create mode 100644 pos_customer_screen_partner_location_google_map/__manifest__.py create mode 100644 pos_customer_screen_partner_location_google_map/readme/CONTRIBUTORS.rst create mode 100644 pos_customer_screen_partner_location_google_map/readme/DESCRIPTION.rst create mode 100644 pos_customer_screen_partner_location_google_map/static/description/index.html create mode 100644 pos_customer_screen_partner_location_google_map/static/src/portal/customer_screen_map.js create mode 120000 setup/pos_customer_screen_partner_location_google_map/odoo/addons/pos_customer_screen_partner_location_google_map create mode 100644 setup/pos_customer_screen_partner_location_google_map/setup.py 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..3ace191917 --- /dev/null +++ b/pos_customer_screen_partner_location_google_map/README.rst @@ -0,0 +1,80 @@ +=============================================== +POS Customer Screen Partner Location Google Map +=============================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:c0346df8555655891c691832f6ce9f12b779ce4f9979626f4cea494cb63af3a4 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github + :target: https://github.com/OCA/pos/tree/16.0/pos_customer_screen_partner_location_google_map + :alt: OCA/pos +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pos-16-0/pos-16-0-pos_customer_screen_partner_location_google_map + :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/pos&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to select partner address directly on google map. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Cetmix + +Contributors +~~~~~~~~~~~~ + +* Cetmix + + * Ivan Sokolov + * Maksim Shurupov + + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/pos `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. 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..f74ba46115 --- /dev/null +++ b/pos_customer_screen_partner_location_google_map/__manifest__.py @@ -0,0 +1,24 @@ +# 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, + "auto_install": True, +} diff --git a/pos_customer_screen_partner_location_google_map/readme/CONTRIBUTORS.rst b/pos_customer_screen_partner_location_google_map/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..8519ee3fa4 --- /dev/null +++ b/pos_customer_screen_partner_location_google_map/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* Cetmix + + * Ivan Sokolov + * Maksim Shurupov + diff --git a/pos_customer_screen_partner_location_google_map/readme/DESCRIPTION.rst b/pos_customer_screen_partner_location_google_map/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..2e00b73fc5 --- /dev/null +++ b/pos_customer_screen_partner_location_google_map/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows to select partner address directly on google map. diff --git a/pos_customer_screen_partner_location_google_map/static/description/index.html b/pos_customer_screen_partner_location_google_map/static/description/index.html new file mode 100644 index 0000000000..f0ef4da6c1 --- /dev/null +++ b/pos_customer_screen_partner_location_google_map/static/description/index.html @@ -0,0 +1,424 @@ + + + + + +POS Customer Screen Partner Location Google Map + + + +
+

POS Customer Screen Partner Location Google Map

+ + +

Beta License: AGPL-3 OCA/pos Translate me on Weblate Try me on Runboat

+

This module allows to select partner address directly on google map.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Cetmix
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/pos project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + 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, +)