From 923816473c7d54907cbe6e232c63ed11e920f12a Mon Sep 17 00:00:00 2001 From: jordyBSK <125542402+jordyBSK@users.noreply.github.com> Date: Thu, 28 Nov 2024 08:08:12 +0100 Subject: [PATCH] T1996 add a link for position in google maps (#1998) * feat: add 'google_link' computed field to display a link to Google Maps with gps_latitude and gps_longitude * feat: add 'google_link' field to display Google Maps link * fix: fix files with pre-commit * Refactor: Refactor _compute_google_link method to avoid E501 line length issue * feat: add the google maps button at the top of the form view * fix: fix child_compassion.py with pre-commit --------- Co-authored-by: jordyBSK --- child_compassion/models/project_compassion.py | 16 ++++++++++++++++ .../views/project_compassion_view.xml | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/child_compassion/models/project_compassion.py b/child_compassion/models/project_compassion.py index aa262b9f7..b05381b66 100644 --- a/child_compassion/models/project_compassion.py +++ b/child_compassion/models/project_compassion.py @@ -80,6 +80,7 @@ class CompassionProject(models.Model): zip_code = fields.Char(readonly=True) gps_latitude = fields.Float(readonly=True) gps_longitude = fields.Float(readonly=True) + google_link = fields.Char(readonly=True, compute="_compute_google_link") timezone = fields.Char(readonly=True, compute="_compute_timezone", store=True) cluster = fields.Char(readonly=True) territory = fields.Char(readonly=True) @@ -531,6 +532,21 @@ def _compute_timezone(self): lng=project.gps_longitude, lat=project.gps_latitude ) + def _compute_google_link(self): + for project in self: + if project.gps_latitude and project.gps_longitude: + project.google_link = f"https://www.google.com/maps/search/?api=1&query={project.gps_latitude},{project.gps_longitude}" + else: + project.google_link = False + + def open_google_maps(self): + self.ensure_one() + return { + "type": "ir.actions.act_url", + "url": self.google_link, + "target": "new", + } + def _compute_usd(self): usd = self.env.ref("base.USD") for project in self: diff --git a/child_compassion/views/project_compassion_view.xml b/child_compassion/views/project_compassion_view.xml index 27a32e5a3..3102216bc 100644 --- a/child_compassion/views/project_compassion_view.xml +++ b/child_compassion/views/project_compassion_view.xml @@ -37,6 +37,13 @@ type="object" icon="fa-globe" class="oe_stat_button" + /> +