-
-
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.
[FIX] pos_partner_location_google_map: QR Code URL field is added.
- Loading branch information
Showing
7 changed files
with
65 additions
and
16 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from . import address_google_struct | ||
from . import base_geocoder | ||
from . import pos_config | ||
from . import res_partner |
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, 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 "" | ||
) |
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from . import common | ||
from . import test_address_google_struct | ||
from . import test_base_geocoder | ||
from . import test_res_partner |
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,36 @@ | ||
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.lat = lat_long_struct["lat"] | ||
self.lng = lat_long_struct["lng"] | ||
self.partner = self.env["res.partner"].create( | ||
{"name": "Bob", "partner_latitude": self.lat, "partner_longitude": self.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.assertEqual( | ||
self.partner.qr_code_url, | ||
self.map_url.format(self.lat, self.lng), | ||
"QR URL must be the same", | ||
) |