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" + /> +