diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-06-10 11:17:57 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-06-10 11:17:57 +0700 |
| commit | 5ca33915f1e3d052cfa989163d43a15dbc9ddec9 (patch) | |
| tree | 828c56626d0c298d17f3b698cc9fb5ae0db1f011 | |
| parent | 2760b81f8a650ea95d36c125d1ab4e2feb011e44 (diff) | |
(andri) add button get koordinat pada contact
| -rw-r--r-- | indoteknik_custom/models/res_partner.py | 27 | ||||
| -rw-r--r-- | indoteknik_custom/views/res_partner.xml | 20 |
2 files changed, 46 insertions, 1 deletions
diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index f1e362e6..0f1edac2 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -3,6 +3,7 @@ from odoo.exceptions import UserError, ValidationError from datetime import datetime from odoo.http import request import re +import requests class GroupPartner(models.Model): _name = 'group.partner' @@ -521,4 +522,28 @@ class ResPartner(models.Model): @api.onchange('name') def _onchange_name(self): if self.company_type == 'person': - self.nama_wajib_pajak = self.name
\ No newline at end of file + self.nama_wajib_pajak = self.name + + def geocode_address(self): + for rec in self: + address = ', '.join(filter(None, [ + rec.street, + rec.city, + rec.state_id.name if rec.state_id else '', + rec.zip, + rec.country_id.name if rec.country_id else '' + ])) + + if not address: + continue + + api_key = self.env['ir.config_parameter'].sudo().get_param('google.maps.api_key') + url = f'https://maps.googleapis.com/maps/api/geocode/json?address={address}&key={api_key}' + response = requests.get(url) + + if response.ok: + result = response.json() + if result.get('results'): + location = result['results'][0]['geometry']['location'] + rec.latitude = location['lat'] + rec.longtitude = location['lng']
\ No newline at end of file diff --git a/indoteknik_custom/views/res_partner.xml b/indoteknik_custom/views/res_partner.xml index 9fb6530c..f4c1be31 100644 --- a/indoteknik_custom/views/res_partner.xml +++ b/indoteknik_custom/views/res_partner.xml @@ -68,6 +68,26 @@ <field name="vat" position="before"> <field name="latitude"/> <field name="longtitude"/> + + <button name="geocode_address" type="object" string="Cari Lokasi dari Alamat" class="btn btn-primary"/> + + <separator string="Map Lokasi"/> + <div style="height: 400px;"> + <t t-if="record.latitude.value and record.longtitude.value"> + <t t-set="google_maps_api_key" t-value="request.env['ir.config_parameter'].sudo().get_param('google.maps.api_key')"/> + <iframe + t-att-src="'https://www.google.com/maps/embed/v1/place?key=' + google_maps_api_key + '&q=' + str(record.latitude.value) + ',' + str(record.longtitude.value)" + width="100%" + height="400" + style="border:0;" + allowfullscreen="" + loading="lazy" + ></iframe> + </t> + <t t-else=""> + <p>Isi alamat lalu klik "Cari Lokasi dari Alamat" untuk menampilkan peta.</p> + </t> + </div> </field> <field name="vat" position="after"> <field name="email_finance" widget="email"/> |
