Skip to content

Commit

Permalink
T1996 add a link for position in google maps (#1998)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
jordyBSK and jordyBSK authored Nov 28, 2024
1 parent 64362c0 commit 9238164
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions child_compassion/models/project_compassion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions child_compassion/views/project_compassion_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
type="object"
icon="fa-globe"
class="oe_stat_button"
/>
<button
name="open_google_maps"
type="object"
string="Google Maps"
icon="fa-external-link"
class="oe_stat_button"
/>
</div>
<div class="oe_title">
Expand Down

0 comments on commit 9238164

Please sign in to comment.