-
-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] pos_customer_screen_partner_location_google_map: Module added.
- Loading branch information
Showing
6 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
23 changes: 23 additions & 0 deletions
23
pos_customer_screen_partner_location_google_map/__manifest__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
119 changes: 119 additions & 0 deletions
119
pos_customer_screen_partner_location_google_map/static/src/portal/customer_screen_map.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); | ||
}, | ||
}); | ||
} | ||
); |
1 change: 1 addition & 0 deletions
1
...n_partner_location_google_map/odoo/addons/pos_customer_screen_partner_location_google_map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../pos_customer_screen_partner_location_google_map |
6 changes: 6 additions & 0 deletions
6
setup/pos_customer_screen_partner_location_google_map/setup.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |