summaryrefslogtreecommitdiff
path: root/indoteknik_custom
diff options
context:
space:
mode:
authorIndoteknik . <it@fixcomart.co.id>2025-06-10 15:47:32 +0700
committerIndoteknik . <it@fixcomart.co.id>2025-06-10 15:47:32 +0700
commitdf0467f8e493840f3013bc58ca26fc6d98793c95 (patch)
tree05a01e1dee6bf866caaecfb5651f849fcf37cf86 /indoteknik_custom
parent5ca33915f1e3d052cfa989163d43a15dbc9ddec9 (diff)
(andri) add openstreetmaps pada contact
Diffstat (limited to 'indoteknik_custom')
-rw-r--r--indoteknik_custom/models/res_partner.py26
-rw-r--r--indoteknik_custom/views/res_partner.xml19
2 files changed, 21 insertions, 24 deletions
diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py
index 0f1edac2..fee0e73b 100644
--- a/indoteknik_custom/models/res_partner.py
+++ b/indoteknik_custom/models/res_partner.py
@@ -146,6 +146,7 @@ class ResPartner(models.Model):
date_payment_terms_purchase = fields.Datetime(string='Date Update Payment Terms')
longtitude = fields.Char(string='Longtitude')
latitude = fields.Char(string='Latitude')
+ map_view = fields.Char(string='Map')
address_map = fields.Char(string='Address Map')
company_type = fields.Selection(string='Company Type',
selection=[('person', 'Individual'), ('company', 'Company')],
@@ -526,12 +527,24 @@ class ResPartner(models.Model):
def geocode_address(self):
for rec in self:
+ # Ambil nama dari relasi (Many2one) atau gunakan nilai default
+ kelurahan = rec.kelurahan_id.name if rec.kelurahan_id else ''
+ kecamatan = rec.kecamatan_id.name if rec.kecamatan_id else ''
+ kota = rec.kota_id.name if rec.kota_id else ''
+ zip_code = rec.zip or ''
+ state = rec.state_id.name if rec.state_id else ''
+ country = rec.country_id.name if rec.country_id else ''
+ street = rec.street or ''
+
+ # Susun alamat lengkap sesuai urutan lokal
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 ''
+ street,
+ kelurahan,
+ kecamatan,
+ kota,
+ zip_code,
+ state,
+ country,
]))
if not address:
@@ -539,6 +552,7 @@ class ResPartner(models.Model):
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:
@@ -546,4 +560,4 @@ class ResPartner(models.Model):
if result.get('results'):
location = result['results'][0]['geometry']['location']
rec.latitude = location['lat']
- rec.longtitude = location['lng'] \ No newline at end of file
+ rec.longtitude = location['lng']
diff --git a/indoteknik_custom/views/res_partner.xml b/indoteknik_custom/views/res_partner.xml
index f4c1be31..c23500c8 100644
--- a/indoteknik_custom/views/res_partner.xml
+++ b/indoteknik_custom/views/res_partner.xml
@@ -70,24 +70,7 @@
<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 + '&amp;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 name="map_view" widget="openstreetmap"/>
</field>
<field name="vat" position="after">
<field name="email_finance" widget="email"/>