From 1601e38f33bfb0c800839e6fc64c07f3579c0561 Mon Sep 17 00:00:00 2001 From: geomer198 Date: Sun, 10 Dec 2023 01:19:58 +0400 Subject: [PATCH] [FIX] pos_partner_location_google_map: QR Code URL field is added. --- pos_partner_location_google_map/README.rst | 13 +----- .../__manifest__.py | 1 - .../models/__init__.py | 1 + .../models/res_partner.py | 25 +++++++++++ .../static/description/index.html | 4 +- .../tests/__init__.py | 1 + .../tests/test_res_partner.py | 41 +++++++++++++++++++ 7 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 pos_partner_location_google_map/models/res_partner.py create mode 100644 pos_partner_location_google_map/tests/test_res_partner.py diff --git a/pos_partner_location_google_map/README.rst b/pos_partner_location_google_map/README.rst index 1cdb6dcc02..9dcae8cf75 100644 --- a/pos_partner_location_google_map/README.rst +++ b/pos_partner_location_google_map/README.rst @@ -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 @@ -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 `__: - -|maintainer-geomer198| |maintainer-CetmixGitDrone| - This module is part of the `OCA/pos `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pos_partner_location_google_map/__manifest__.py b/pos_partner_location_google_map/__manifest__.py index ca5b51e45b..426c1d3d9c 100644 --- a/pos_partner_location_google_map/__manifest__.py +++ b/pos_partner_location_google_map/__manifest__.py @@ -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"], diff --git a/pos_partner_location_google_map/models/__init__.py b/pos_partner_location_google_map/models/__init__.py index a8858868ce..8df20b924a 100644 --- a/pos_partner_location_google_map/models/__init__.py +++ b/pos_partner_location_google_map/models/__init__.py @@ -1,3 +1,4 @@ from . import address_google_struct from . import base_geocoder from . import pos_config +from . import res_partner diff --git a/pos_partner_location_google_map/models/res_partner.py b/pos_partner_location_google_map/models/res_partner.py new file mode 100644 index 0000000000..28f4e4279d --- /dev/null +++ b/pos_partner_location_google_map/models/res_partner.py @@ -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 "" + ) diff --git a/pos_partner_location_google_map/static/description/index.html b/pos_partner_location_google_map/static/description/index.html index 69c05b0f9b..ee371e908e 100644 --- a/pos_partner_location_google_map/static/description/index.html +++ b/pos_partner_location_google_map/static/description/index.html @@ -367,7 +367,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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/pos Translate me on Weblate Try me on Runboat

This module allows to select partner address directly on map.

@@ -419,8 +419,6 @@

Maintainers

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.

-

Current maintainers:

-

geomer198 CetmixGitDrone

This module is part of the OCA/pos project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/pos_partner_location_google_map/tests/__init__.py b/pos_partner_location_google_map/tests/__init__.py index c7a0ef4b65..6a61418bb1 100644 --- a/pos_partner_location_google_map/tests/__init__.py +++ b/pos_partner_location_google_map/tests/__init__.py @@ -1,3 +1,4 @@ from . import common from . import test_address_google_struct from . import test_base_geocoder +from . import test_res_partner diff --git a/pos_partner_location_google_map/tests/test_res_partner.py b/pos_partner_location_google_map/tests/test_res_partner.py new file mode 100644 index 0000000000..4a4db7c99f --- /dev/null +++ b/pos_partner_location_google_map/tests/test_res_partner.py @@ -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", + )