diff options
Diffstat (limited to 'indoteknik_custom')
| -rw-r--r-- | indoteknik_custom/models/res_partner.py | 77 | ||||
| -rw-r--r-- | indoteknik_custom/views/res_partner.xml | 5 |
2 files changed, 80 insertions, 2 deletions
diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index eeb8b67d..82aa1134 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -4,6 +4,8 @@ from datetime import datetime from odoo.http import request import re import requests +import logging +_logger = logging.getLogger(__name__) class GroupPartner(models.Model): _name = 'group.partner' @@ -583,3 +585,78 @@ class ResPartner(models.Model): raise UserError("Tidak ditemukan hasil geocode untuk alamat tersebut.") else: raise UserError("Permintaan ke Google Maps gagal. Periksa koneksi internet atau API Key.") + + # def _update_address_from_coords(self): + # for rec in self: + # if rec.latitude and rec.longtitude: + # address = self.reverse_geocode(rec.latitude, rec.longtitude) + # if not address: + # continue + + # updates = { + # 'street': address.get('road') or '', + # 'zip': address.get('postcode') or '', + # 'city': address.get('city') or address.get('town') or address.get('village') or '', + # } + + # # Kelurahan (vit.kelurahan) + # if address.get('suburb'): + # kel = self.env['vit.kelurahan'].search([ + # ('name', 'ilike', address['suburb']) + # ], limit=1) + # if kel: + # updates['kelurahan_id'] = kel.id + + # # Kecamatan (vit.kecamatan) + # kec_nama = address.get('district') or address.get('village') + # if kec_nama: + # kec = self.env['vit.kecamatan'].search([ + # ('name', 'ilike', kec_nama) + # ], limit=1) + # if kec: + # updates['kecamatan_id'] = kec.id + + # # Kota (vit.kota) + # kota_nama = address.get('city') or address.get('town') + # if kota_nama: + # kota = self.env['vit.kota'].search([ + # ('name', 'ilike', kota_nama) + # ], limit=1) + # if kota: + # updates['kota_id'] = kota.id + + # # Provinsi (res.country.state) + # if address.get('state'): + # state = self.env['res.country.state'].search([ + # ('name', 'ilike', address['state']) + # ], limit=1) + # if state: + # updates['state_id'] = state.id + + # # Negara (res.country) + # if address.get('country_code'): + # country = self.env['res.country'].search([ + # ('code', '=', address['country_code'].upper()) + # ], limit=1) + # if country: + # updates['country_id'] = country.id + + # rec.write(updates) + + + + # def reverse_geocode(self, lat, lon): + # try: + # url = f'https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat={lat}&lon={lon}' + # headers = { + # 'User-Agent': 'Odoo/1.0 (andrifebriyadiputra@gmail.com)', # WAJIB: ganti dengan email domain kamu + # } + # response = requests.get(url, headers=headers, timeout=5) + # if response.ok: + # data = response.json() + # return data.get('address', {}) + # else: + # _logger.warning("Reverse geocode failed with status %s: %s", response.status_code, response.text) + # except Exception as e: + # _logger.exception("Exception during reverse geocode: %s", e) + # return {} diff --git a/indoteknik_custom/views/res_partner.xml b/indoteknik_custom/views/res_partner.xml index 85ee5ef0..4cee0c47 100644 --- a/indoteknik_custom/views/res_partner.xml +++ b/indoteknik_custom/views/res_partner.xml @@ -66,14 +66,15 @@ <field name="leadtime"/> </group> <xpath expr="//notebook/page[@name='contact_addresses']" position="before"> - <page string="Pin Point Location" name="map_location"> + <page string="Pin Point Location" name="map_location" autofocus="autofocus"> <group> <button name="geocode_address" type="object" string="Get Pin Point Location" class="btn btn-primary"/> </group> <div style="margin: 16px 0;"> - <field name="map_view" widget="openstreetmap" nolabel="1" style="width: 100%;"/> + <field name="map_view" widget="googlemap" nolabel="1"/> </div> <group> + <field name="address_map"/> <field name="latitude" readonly="1"/> <field name="longtitude" readonly="1"/> </group> |
