Skip to content

Commit

Permalink
Merge PR #1002 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
OCA-git-bot committed Apr 2, 2024
2 parents acda7ae + 0cbc999 commit a34eb1e
Show file tree
Hide file tree
Showing 47 changed files with 2,370 additions and 0 deletions.
90 changes: 90 additions & 0 deletions pos_partner_location_abstract/README.rst
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.
1 change: 1 addition & 0 deletions pos_partner_location_abstract/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
25 changes: 25 additions & 0 deletions pos_partner_location_abstract/__manifest__.py
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,
}
4 changes: 4 additions & 0 deletions pos_partner_location_abstract/models/__init__.py
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
82 changes: 82 additions & 0 deletions pos_partner_location_abstract/models/address_struct.py
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
28 changes: 28 additions & 0 deletions pos_partner_location_abstract/models/pos_config.py
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

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)
18 changes: 18 additions & 0 deletions pos_partner_location_abstract/models/pos_session.py
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
31 changes: 31 additions & 0 deletions pos_partner_location_abstract/models/res_partner.py
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)
4 changes: 4 additions & 0 deletions pos_partner_location_abstract/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* Cetmix <https://cetmix.com/>

* Ivan Sokolov
* Maksim Shurupov
5 changes: 5 additions & 0 deletions pos_partner_location_abstract/readme/DESCRIPTION.rst
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.
3 changes: 3 additions & 0 deletions pos_partner_location_abstract/readme/ROADMAP.rst
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.
Loading

0 comments on commit a34eb1e

Please sign in to comment.