summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorIndoteknik . <it@fixcomart.co.id>2025-06-12 19:26:46 +0700
committerIndoteknik . <it@fixcomart.co.id>2025-06-12 19:26:46 +0700
commita921017a829ebef8442740fac964260d98566e6a (patch)
tree8954724c74fc7e5cfe6d9387b9113854863e6b82 /indoteknik_custom/models
parent8ac5d556a6686c6b81d5e9178bff5d308e8f176f (diff)
(andri) try gmaps sebagai pengganti openstreetmaps
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/res_partner.py77
1 files changed, 77 insertions, 0 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 {}