-
-
Notifications
You must be signed in to change notification settings - Fork 602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[16.0][ADD] pos_partner_location_map #1002
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
============================= | ||
POS Partner Location Abstract | ||
============================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:a9eae0fc2c410a71ba3062148599802fe9f4f89143bb1e37d0b78b60f9542daa | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
.. |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_partner_location_abstract | ||
: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_partner_location_abstract | ||
: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 implements base functionality for using different map providers in POS. | ||
It allows to select partner location directly on a map and stores selected location in the res.partner model. | ||
It also tries to evaluate partner's address from coordinates and provides a helper function that generates location QR code. | ||
|
||
NB: This is a core module which is meant to be used in further customisations. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
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. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/pos/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 <https://github.com/OCA/pos/issues/new?body=module:%20pos_partner_location_abstract%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Cetmix | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Cetmix <https://cetmix.com/> | ||
|
||
* 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 <https://github.com/OCA/pos/tree/16.0/pos_partner_location_abstract>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (C) 2023 Cetmix OÜ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"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)", | ||
"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", | ||
], | ||
"web.assets_tests": [ | ||
"pos_partner_location_abstract/static/src/tests/tours/*.tour.esm.js", # noqa | ||
], | ||
}, | ||
"installable": True, | ||
} |
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_partner |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Copyright (C) 2023 Cetmix OÜ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (C) 2023 Cetmix OÜ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
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 | ||
Comment on lines
+12
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand very well why both functions are required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
These functions helping fast and without problems configure new providers for POS. |
||
|
||
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (C) 2023 Cetmix OÜ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class PosSession(models.Model): | ||
_inherit = "pos.session" | ||
|
||
def _loader_params_res_partner(self): | ||
res = super()._loader_params_res_partner() | ||
# Add addresses fields | ||
res["search_params"]["fields"] += [ | ||
"contact_address", | ||
"partner_latitude", | ||
"partner_longitude", | ||
] | ||
return res |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (C) 2023 Cetmix OÜ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import logging | ||
|
||
from odoo import api, fields, models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
qr_code_url = fields.Char(compute="_compute_qr_code_url") | ||
|
||
def _compute_qr_code_url(self): | ||
"""Compute QR Code URL for map provider""" | ||
self.update({"qr_code_url": ""}) | ||
|
||
@api.model | ||
def create_from_ui(self, partner): | ||
try: | ||
lat = float(partner.get("partner_latitude")) | ||
except (TypeError, ValueError): | ||
lat = False | ||
try: | ||
lng = float(partner.get("partner_longitude")) | ||
except (TypeError, ValueError): | ||
lng = False | ||
partner.update(partner_latitude=lat, partner_longitude=lng) | ||
return super().create_from_ui(partner) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* Cetmix <https://cetmix.com/> | ||
|
||
* Ivan Sokolov | ||
* Maksim Shurupov |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This module implements base functionality for using different map providers in POS. | ||
It allows to select partner location directly on a map and stores selected location in the res.partner model. | ||
It also tries to evaluate partner's address from coordinates and provides a helper function that generates location QR code. | ||
|
||
NB: This is a core module which is meant to be used in further customisations. |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand this field correctly, this should be a Selection field, don't you think ? (openstreetmap / googlemap). don't you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thinks it's not better idea. This field is compute by
Geo Provider
configuration parameter. Provider we can update or add new what raise an error, that is why this field is just Char.