Skip to content

Commit

Permalink
[FIX] pos_partner_location_google_map: QR Code URL field is added.
Browse files Browse the repository at this point in the history
  • Loading branch information
geomer198 committed Dec 9, 2023
1 parent c78d0bc commit 1601e38
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 16 deletions.
13 changes: 1 addition & 12 deletions pos_partner_location_google_map/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ POS Partner Location Google Map
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6f57881f4d3e7d3c6903b80194fc44ffc3ffa5bffe62f4ff75db798a45ca762c
!! source digest: sha256:654b38b90eddce0065c8f366cf0266b53223d6be41750edf9362829444d97214
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -78,17 +78,6 @@ 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.

.. |maintainer-geomer198| image:: https://github.com/geomer198.png?size=40px
:target: https://github.com/geomer198
:alt: geomer198
.. |maintainer-CetmixGitDrone| image:: https://github.com/CetmixGitDrone.png?size=40px
:target: https://github.com/CetmixGitDrone
:alt: CetmixGitDrone

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-geomer198| |maintainer-CetmixGitDrone|

This module is part of the `OCA/pos <https://github.com/OCA/pos/tree/16.0/pos_partner_location_google_map>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 0 additions & 1 deletion pos_partner_location_google_map/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"category": "Point Of Sale",
"summary": "POS Partner Location Google Map",
"author": "Cetmix, Odoo Community Association (OCA)",
"maintainers": ["geomer198", "CetmixGitDrone"],
"website": "https://github.com/OCA/pos",
"license": "AGPL-3",
"depends": ["pos_partner_location_abstract"],
Expand Down
1 change: 1 addition & 0 deletions pos_partner_location_google_map/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import address_google_struct
from . import base_geocoder
from . import pos_config
from . import res_partner
25 changes: 25 additions & 0 deletions pos_partner_location_google_map/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from odoo import api, models


class ResPartner(models.Model):
_inherit = "res.partner"

@api.model
def _get_map_provider_tech_name(self):
"""Get map provider technical name"""
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))
return provider.tech_name

def _compute_qr_code_url(self):
if self._get_map_provider_tech_name() != "googlemap":
return super()._compute_qr_code_url()
map_url = "https://maps.google.com/maps?q={},{}"
for rec in self:
rec.qr_code_url = (
map_url.format(rec.partner_latitude, rec.partner_longitude)
if rec.partner_latitude and rec.partner_longitude
else ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">POS Partner Location Google Map</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6f57881f4d3e7d3c6903b80194fc44ffc3ffa5bffe62f4ff75db798a45ca762c
!! source digest: sha256:654b38b90eddce0065c8f366cf0266b53223d6be41750edf9362829444d97214
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/pos/tree/16.0/pos_partner_location_google_map"><img alt="OCA/pos" src="https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/pos-16-0/pos-16-0-pos_partner_location_google_map"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/pos&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to select partner address directly on map.</p>
Expand Down Expand Up @@ -419,8 +419,6 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>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.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/geomer198"><img alt="geomer198" src="https://github.com/geomer198.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/CetmixGitDrone"><img alt="CetmixGitDrone" src="https://github.com/CetmixGitDrone.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/pos/tree/16.0/pos_partner_location_google_map">OCA/pos</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
Expand Down
1 change: 1 addition & 0 deletions pos_partner_location_google_map/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import common
from . import test_address_google_struct
from . import test_base_geocoder
from . import test_res_partner
41 changes: 41 additions & 0 deletions pos_partner_location_google_map/tests/test_res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from odoo.tests import TransactionCase

from .common import RESPONSE_MAP


class TestResPartner(TransactionCase):
def setUp(self):
super().setUp()
self.provider_google_map = self.env.ref(
"base_geolocalize.geoprovider_google_map"
)
lat_long_struct = RESPONSE_MAP["result"]["geometry"]["location"]
self.partner = self.env["res.partner"].create(
{
"name": "Bob",
"partner_latitude": lat_long_struct["lat"],
"partner_longitude": lat_long_struct["lng"],
}
)
self.map_url = "https://maps.google.com/maps?q={},{}"

def test_compute_qr_code_url_provider(self):
"""Test flow that computes qr code url by provider"""
# Without provider
self.env["ir.config_parameter"].set_param(
"base_geolocalize.geo_provider", False
)
self.assertEqual(self.partner.qr_code_url, "", "QR URL must be empty")

# Google provider
self.env["ir.config_parameter"].set_param(
"base_geolocalize.geo_provider", self.provider_google_map.id
)
self.partner._compute_qr_code_url()
self.assertEqual(
self.partner.qr_code_url,
self.map_url.format(
self.partner.partner_latitude, self.partner.partner_longitude
),
"QR URL must be the same",
)

0 comments on commit 1601e38

Please sign in to comment.