-
-
Notifications
You must be signed in to change notification settings - Fork 602
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_abstract: Module added.
- Loading branch information
Showing
22 changed files
with
521 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,20 @@ | ||
{ | ||
"name": "POS Partner Location Abstract", | ||
"version": "16.0.1.0.0", | ||
"category": "Point Of Sale", | ||
"summary": "POS Partner Location Abstract", | ||
"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": [], | ||
"assets": { | ||
"point_of_sale.assets": [ | ||
"pos_partner_location_abstract/static/src/css/*.css", | ||
"pos_partner_location_abstract/static/src/js/*.js", | ||
"pos_partner_location_abstract/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,4 @@ | ||
from . import address_struct | ||
from . import pos_config | ||
from . import pos_session | ||
from . import res_config_settings |
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,79 @@ | ||
import requests | ||
|
||
|
||
class AddressStruct(object): | ||
ADDR_FIELDS = {} | ||
ODOO_ADDR = [ | ||
"street", | ||
"city", | ||
"state_id", | ||
"country_id", | ||
"zip", | ||
] | ||
SERVICE_URL = None | ||
|
||
def __init__(self, odoo_env): | ||
self._result = {} | ||
self.env = odoo_env | ||
self.status = None | ||
|
||
@property | ||
def street(self): | ||
""" | ||
Street name | ||
:rtype str | bool | ||
""" | ||
return False | ||
|
||
@property | ||
def city(self): | ||
""" | ||
City name | ||
:rtype: str | bool | ||
""" | ||
return False | ||
|
||
@property | ||
def state_id(self): | ||
""" | ||
Fed. State | ||
:rtype: record (res.country.state) | bool | ||
""" | ||
return False | ||
|
||
@property | ||
def country_id(self): | ||
""" | ||
Country | ||
:rtype: record (res.country) | bool | ||
""" | ||
return False | ||
|
||
@property | ||
def zip(self): | ||
""" | ||
Zip code | ||
:rtype: str | bool | ||
""" | ||
return False | ||
|
||
def get_result(self): | ||
""" | ||
Get result for updating contact address | ||
:return:fields values | ||
:rtype: dict | ||
""" | ||
return {item: getattr(self, item) for item in self.ODOO_ADDR} | ||
|
||
def query_addr(self, params, timeout=5): | ||
""" | ||
Query to service for get address result | ||
:param dict params: query params | ||
:param int timeout: request timeout | ||
:return: json object | ||
:rtype: dict | bool | ||
""" | ||
response = requests.get(self.SERVICE_URL, params, timeout=timeout) | ||
if response.status_code == 200: | ||
return response.json() | ||
return 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,25 @@ | ||
from odoo import api, fields, models | ||
|
||
|
||
class PosConfig(models.Model): | ||
_inherit = "pos.config" | ||
|
||
geolocalize_tech_name = fields.Char(compute="_compute_geolocalize") | ||
|
||
@api.model | ||
def _set_extended_data(self): | ||
return {} | ||
|
||
def _set_pos_config_parameter(self, tech_name, ext_vals=None): | ||
_ = ext_vals or {} | ||
for config in self: | ||
config.geolocalize_tech_name = tech_name | ||
|
||
def _compute_geolocalize(self): | ||
ICPSudo = self.env["ir.config_parameter"].sudo() | ||
geo_provider_obj = self.env["base.geo_provider"] | ||
geo_provider_id = ICPSudo.get_param("base_geolocalize.geo_provider") | ||
provider = geo_provider_obj.browse(int(geo_provider_id)) | ||
tech_name = provider.tech_name | ||
ext_vals = self._set_extended_data() | ||
self._set_pos_config_parameter(tech_name, ext_vals) |
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 @@ | ||
from odoo import models | ||
|
||
|
||
class PosSession(models.Model): | ||
_inherit = "pos.session" | ||
|
||
def _loader_params_res_partner(self): | ||
res = super(PosSession, self)._loader_params_res_partner() | ||
# Add addresses fields | ||
res["search_params"]["fields"] += [ | ||
"contact_address", | ||
"partner_latitude", | ||
"partner_longitude", | ||
] | ||
return res |
10 changes: 10 additions & 0 deletions
10
pos_partner_location_abstract/models/res_config_settings.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,10 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
auto_create_map_data = fields.Boolean( | ||
config_parameter="pos_partner_location_abstract.auto_create_map_data", | ||
string="Auto Create Regions", | ||
) |
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 @@ | ||
* Cetmix <https://cetmix.com/> |
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 @@ | ||
This module is base for module pos_partner_location_google_map (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,3 @@ | ||
As for the release date module `pos_partner_location_google_map` supports only Google Maps API. | ||
|
||
Contribute to this module by adding other provider such as OpenStreetMap. |
17 changes: 17 additions & 0 deletions
17
pos_partner_location_abstract/static/src/css/map_popup.css
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,17 @@ | ||
.partner-map-popup { | ||
max-width: 90% !important; | ||
height: 90% !important; | ||
} | ||
|
||
.partner-map-body { | ||
height: 80% !important; | ||
padding: 0.5rem; | ||
} | ||
|
||
.map-addr-input { | ||
margin-top: 10px; | ||
margin-left: 10px; | ||
margin-right: 10px; | ||
height: 40px !important; | ||
width: 100% !important; | ||
} |
69 changes: 69 additions & 0 deletions
69
pos_partner_location_abstract/static/src/js/PartnerDetailsMapEdit.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,69 @@ | ||
/** @odoo-module alias=pos_partner_location_abstract.PartnerDetailsMapEdit **/ | ||
|
||
import { | ||
ConnectionAbortedError, | ||
ConnectionLostError, | ||
} from "@web/core/network/rpc_service"; | ||
import PartnerDetailsEdit from "point_of_sale.PartnerDetailsEdit"; | ||
import Registries from "point_of_sale.Registries"; | ||
import {identifyError} from "point_of_sale.utils"; | ||
|
||
const PartnerDetailsMapEdit = (PartnerDetailsEdit) => | ||
class PartnerDetailsMapEdit extends PartnerDetailsEdit { | ||
get accessToMap() { | ||
return false; | ||
} | ||
|
||
async partnerMap() { | ||
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; | ||
if (Array.isArray(value)) { | ||
this.changes[key] = value[0]; | ||
} else { | ||
this.changes[key] = value; | ||
} | ||
} | ||
this.render(this); | ||
} | ||
} | ||
|
||
async openMap() { | ||
try { | ||
if (this.accessToMap) { | ||
await this.partnerMap(); | ||
} else { | ||
this.showPopup("ErrorPopup", { | ||
title: this.env._t("Map Error"), | ||
body: this.env._t("Cannot access map functions!"), | ||
}); | ||
} | ||
} 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); | ||
|
||
export default PartnerDetailsMapEdit; |
50 changes: 50 additions & 0 deletions
50
pos_partner_location_abstract/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,50 @@ | ||
/** @odoo-module alias=pos_partner_location_abstract.PartnerMapEdit **/ | ||
|
||
import AbstractAwaitablePopup from "point_of_sale.AbstractAwaitablePopup"; | ||
import Registries from "point_of_sale.Registries"; | ||
import {useRef} from "@odoo/owl"; | ||
|
||
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.mapContainerRef = useRef("map-container"); | ||
this.addrInput = useRef("addr-input"); | ||
this.config = this.env.pos.config; | ||
this.provider = ""; | ||
this.onHandleMap(); | ||
} | ||
|
||
onHandleMap() { | ||
return false; | ||
} | ||
|
||
async getPayload() { | ||
return { | ||
partner_latitude: this.lat, | ||
partner_longitude: this.lng, | ||
...this.address, | ||
}; | ||
} | ||
|
||
update_marker(lat, lng) { | ||
this.lat = lat; | ||
this.lng = lng; | ||
} | ||
|
||
/* eslint no-empty-function: "warn"*/ | ||
/* eslint no-unused-vars: "warn"*/ | ||
setAddressByLocation(addres) {} | ||
|
||
inputChange(event) { | ||
this.setAddressByLocation(event.target.value); | ||
} | ||
} | ||
PartnerMapEdit.template = "PartnerMapEdit"; | ||
|
||
Registries.Component.add(PartnerMapEdit); | ||
|
||
export default PartnerMapEdit; |
44 changes: 44 additions & 0 deletions
44
pos_partner_location_abstract/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,44 @@ | ||
<?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 | ||
t-if="accessToMap" | ||
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">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> |
29 changes: 29 additions & 0 deletions
29
pos_partner_location_abstract/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,29 @@ | ||
<?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" style="display: flex !important;"> | ||
<input | ||
class="flex-grow-1 map-addr-input" | ||
name="address" | ||
t-ref="addr-input" | ||
placeholder="Address" | ||
t-on-change="inputChange" | ||
/> | ||
<div class="button cancel " t-on-click="cancel"> | ||
Close | ||
</div> | ||
<div class="button confirm disable highlight" t-on-click="confirm"> | ||
Confirm | ||
</div> | ||
</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,3 @@ | ||
from . import test_address_struct | ||
from . import test_pos_config | ||
from . import test_pos_session |
Oops, something went wrong.