-
-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] pos_partner_location_map: Add Module.
- Loading branch information
Showing
18 changed files
with
354 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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 @@ | ||
from . import models |
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,22 @@ | ||
{ | ||
"name": "Point of Sale - Customer Screen", | ||
"version": "16.0.1.0.0", | ||
"category": "Point Of Sale", | ||
"summary": "Point of Sale - Customers can easily interact with point of sale", | ||
"author": "Cetmix,Odoo Community Association (OCA)", | ||
"maintainers": ["geomer198", "CetmixGitDrone"], | ||
"website": "https://github.com/OCA/pos", | ||
"license": "AGPL-3", | ||
"depends": ["base_geolocalize", "point_of_sale"], | ||
"data": [ | ||
"views/res_partner_views.xml", | ||
], | ||
"assets": { | ||
"point_of_sale.assets": [ | ||
"pos_partner_location_map/static/src/css/*.css", | ||
"pos_partner_location_map/static/src/js/*.esm.js", | ||
"pos_partner_location_map/static/src/xml/*.xml", | ||
], | ||
}, | ||
"installable": True, | ||
} |
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,2 @@ | ||
from . import pos_session | ||
from . import res_partner |
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,22 @@ | ||
from odoo import api, models | ||
|
||
|
||
class PosSession(models.Model): | ||
_inherit = "pos.session" | ||
|
||
def _loader_params_res_partner(self): | ||
res = super()._loader_params_res_partner() | ||
res["search_params"]["fields"] += [ | ||
"map_partner_address", | ||
"partner_latitude", | ||
"partner_longitude", | ||
] | ||
return res | ||
|
||
@api.model | ||
def get_google_map_api_key(self): | ||
return ( | ||
self.env["ir.config_parameter"] | ||
.sudo() | ||
.get_param("base_geolocalize.google_map_api_key", False) | ||
) |
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,7 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
map_partner_address = fields.Char() |
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,2 @@ | ||
In General Settings -> Integrations enable the Geo Localisation checkbox. | ||
Select provided and add API key. NB: only google maps are currently supported. |
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,2 @@ | ||
This module allows to select partner address directly on map. | ||
For this Google Maps are used. |
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,3 @@ | ||
In POS open customer list, select a customer and click "Details". | ||
On the customer form click on the "globe" icon and select a location on map. | ||
Click "Save" to save the location. |
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,15 @@ | ||
.partner-map-popup { | ||
max-width: 90% !important; | ||
height: 100% !important; | ||
} | ||
|
||
.partner-map-body { | ||
height: 80% !important; | ||
padding: 0.5rem; | ||
} | ||
|
||
.map-addr-input { | ||
float: left; | ||
margin-top: 10px; | ||
margin-left: 10px; | ||
} |
53 changes: 53 additions & 0 deletions
53
pos_partner_location_map/static/src/js/PartnerDetailsEdit.esm.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,53 @@ | ||
odoo.define("pos_partner_location_map.PartnerDetailsEdit", function (require) { | ||
const PartnerDetailsEdit = require("point_of_sale.PartnerDetailsEdit"); | ||
const Registries = require("point_of_sale.Registries"); | ||
const { | ||
ConnectionLostError, | ||
ConnectionAbortedError, | ||
} = require("@web/core/network/rpc_service"); | ||
const {identifyError} = require("point_of_sale.utils"); | ||
|
||
const PartnerDetailsMapEdit = (PartnerDetailsEdit) => | ||
class PartnerDetailsMapEdit extends PartnerDetailsEdit { | ||
async openMap() { | ||
try { | ||
const {confirmed, payload} = await this.showPopup( | ||
"PartnerMapEdit", | ||
{ | ||
partner: this.props.partner, | ||
} | ||
); | ||
if (confirmed) { | ||
for (const [key, value] of Object.entries(payload)) { | ||
this.props.partner[key] = value; | ||
this.changes[key] = value; | ||
} | ||
this.render(this); | ||
} | ||
} catch (e) { | ||
if ( | ||
identifyError(e) instanceof ConnectionLostError || | ||
ConnectionAbortedError | ||
) { | ||
this.showPopup("OfflineErrorPopup", { | ||
title: this.env._t("Network Error"), | ||
body: this.env._t( | ||
"Cannot access product information screen if offline." | ||
), | ||
}); | ||
} else { | ||
this.showPopup("ErrorPopup", { | ||
title: this.env._t("Unknown error"), | ||
body: this.env._t( | ||
"An unknown error prevents us from loading product information." | ||
), | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
Registries.Component.extend(PartnerDetailsEdit, PartnerDetailsMapEdit); | ||
|
||
return PartnerDetailsMapEdit; | ||
}); |
104 changes: 104 additions & 0 deletions
104
pos_partner_location_map/static/src/js/PartnerMapEdit.esm.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,104 @@ | ||
odoo.define("pos_partner_location_map.PartnerMapEdit", function (require) { | ||
require("pos_partner_location_map.googleMapInit"); | ||
|
||
const AbstractAwaitablePopup = require("point_of_sale.AbstractAwaitablePopup"); | ||
const Registries = require("point_of_sale.Registries"); | ||
const {useRef, onMounted} = owl; | ||
|
||
/* eslint no-undef: "warn"*/ | ||
class PartnerMapEdit extends AbstractAwaitablePopup { | ||
setup() { | ||
super.setup(); | ||
this.partner = this.props.partner; | ||
this.lat = parseFloat(this.partner.partner_latitude) || 0; | ||
this.lng = parseFloat(this.partner.partner_longitude) || 0; | ||
this.address = this.partner.map_partner_address || ""; | ||
this.mapContainerRef = useRef("map-container"); | ||
this.addrInput = useRef("addr-input"); | ||
this.state = { | ||
mapIsShow: false, | ||
}; | ||
this.geocoder = new google.maps.Geocoder(); | ||
onMounted(() => this.googleMapConfigure()); | ||
} | ||
|
||
googleMapConfigure() { | ||
// Default latLng | ||
const latLng = new google.maps.LatLng(this.lat, this.lng); | ||
this.setAddressByLatLng(this.lat, this.lng); | ||
// Config | ||
const mapOptions = { | ||
zoom: 12, | ||
center: latLng, | ||
}; | ||
// Show Map | ||
this.map = new google.maps.Map(this.mapContainerRef.el, mapOptions); | ||
this.marker = new google.maps.Marker({ | ||
position: latLng, | ||
map: this.map, | ||
draggable: true, | ||
}); | ||
this.addrInput.el.value = this.partner.map_partner_address; | ||
|
||
this.map.addListener("click", (event) => { | ||
const lat = event.latLng.lat(); | ||
const lng = event.latLng.lng(); | ||
this.update_marker(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.address = results[0].formatted_address; | ||
this.addrInput.el.value = this.address; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
update_marker(lat, lng) { | ||
this.lat = lat; | ||
this.lng = lng; | ||
const latLng = new google.maps.LatLng(lat, lng); | ||
this.map.setCenter(latLng); | ||
this.marker.setPosition(latLng); | ||
google.maps.event.trigger(this.map, "resize"); | ||
} | ||
|
||
async getPayload() { | ||
return { | ||
partner_latitude: this.lat, | ||
partner_longitude: this.lng, | ||
map_partner_address: this.address, | ||
}; | ||
} | ||
|
||
setAddressByLocation(address) { | ||
if (address) { | ||
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.address = results[0].formatted_address; | ||
this.addrInput.el.value = this.address; | ||
this.update_marker(this.lat, this.lng); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
inputChange(event) { | ||
this.setAddressByLocation(event.target.value); | ||
} | ||
} | ||
|
||
PartnerMapEdit.template = "PartnerMapEdit"; | ||
|
||
Registries.Component.add(PartnerMapEdit); | ||
|
||
return PartnerMapEdit; | ||
}); |
16 changes: 16 additions & 0 deletions
16
pos_partner_location_map/static/src/js/googleMapInit.esm.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,16 @@ | ||
odoo.define("pos_partner_location_map.googleMapInit", function (require) { | ||
const rpc = require("web.rpc"); | ||
const {loadJS} = require("@web/core/assets"); | ||
|
||
rpc.query({ | ||
model: "pos.session", | ||
method: "get_google_map_api_key", | ||
args: [], | ||
}).then((response) => { | ||
loadJS( | ||
"https://maps.googleapis.com/maps/api/js?key=" + | ||
response + | ||
"&libraries=places" | ||
); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
pos_partner_location_map/static/src/xml/PartnerDetailsEdit.xml
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,53 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates id="template" xml:space="preserve"> | ||
|
||
|
||
<t | ||
t-name="PartnerDetailsEdit" | ||
t-inherit="point_of_sale.PartnerDetailsEdit" | ||
t-inherit-mode="extension" | ||
owl="1" | ||
> | ||
<xpath expr="//input[@name='name']" position="after"> | ||
<button | ||
class="button partner-location" | ||
t-on-click="openMap" | ||
style="font-size: 24px" | ||
> | ||
<i class="fa fa-map-marker" /> | ||
</button> | ||
</xpath> | ||
<xpath expr="//div[hasclass('partner-details-left')]" position="inside"> | ||
<div class="partner-detail"> | ||
<span class="label">Map Address</span> | ||
<input | ||
class="detail" | ||
name="map_partner_address" | ||
t-on-change="captureChange" | ||
t-att-value="props.partner.map_partner_address || ''" | ||
placeholder="Map Partner Address" | ||
/> | ||
</div> | ||
<div class="partner-detail"> | ||
<span class="label">Lat/Long</span> | ||
<input | ||
class="detail" | ||
name="partner_latitude" | ||
t-on-change="captureChange" | ||
t-att-value="props.partner.partner_latitude || ''" | ||
placeholder="Latitude" | ||
style="width: 170px" | ||
/> | ||
<input | ||
class="detail" | ||
name="partner_longitude" | ||
t-on-change="captureChange" | ||
t-att-value="props.partner.partner_longitude || ''" | ||
placeholder="Longitude" | ||
style="width: 170px" | ||
/> | ||
</div> | ||
</xpath> | ||
</t> | ||
|
||
</templates> |
30 changes: 30 additions & 0 deletions
30
pos_partner_location_map/static/src/xml/PartnerMapEdit.xml
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,30 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates id="template" xml:space="preserve"> | ||
|
||
<t t-name="PartnerMapEdit" owl="1"> | ||
<div class="popup partner-map-popup"> | ||
<header class="title"> | ||
Customer <t t-esc="partner.name" /> | ||
Location | ||
</header> | ||
<main class="partner-map-body" t-ref="map-container" /> | ||
|
||
<footer class="footer"> | ||
<div class="button confirm disable highlight" t-on-click="confirm"> | ||
Confirm | ||
</div> | ||
<div class="button cancel" t-on-click="cancel"> | ||
Close | ||
</div> | ||
<input | ||
class="map-addr-input" | ||
name="address" | ||
t-ref="addr-input" | ||
placeholder="Address" | ||
t-on-change="inputChange" | ||
/> | ||
</footer> | ||
</div> | ||
</t> | ||
|
||
</templates> |
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,15 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
|
||
<record id="view_partner_form" model="ir.ui.view"> | ||
<field name="name">res.partner.location.map.form</field> | ||
<field name="model">res.partner</field> | ||
<field name="inherit_id" ref="base.view_partner_form" /> | ||
<field name="arch" type="xml"> | ||
<div class="o_address_format" position="after"> | ||
<field name="map_partner_address" /> | ||
</div> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
1 change: 1 addition & 0 deletions
1
setup/pos_partner_location_map/odoo/addons/pos_partner_location_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_partner_location_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,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |